Switch statement "Process finished with exit code 11"
Hello,
My program works fine, but if I choose case 1, enter a name, choose case 0, then choose case 1 again i get "Process finished with exit code 11". Not sure why but if anyone could help thatd be much appreciated!
Thanks,
-Nick
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct list{
char name; //info in node
struct list *link;
}node;
node *getnode();
int main() {
char ch;
int temp = 1;
//creating node
node *a = getnode();
a -> link = NULL;
while (temp == 1) {
printf("\n0. Call a customer");
printf("\n1. Add a customer");
printf("\n2. Quit");
printf("\nPlease input your command (0-2): ");
scanf("%d", &ch);
switch (ch){
case 0:
if(a != NULL) {
while(a != NULL) {
printf("\nCustomer name: %s", &a->name);
a = a->link;
break;
}
}
else
{
printf("\n-->WARNING: there are currently no customers in line<--");
}
break;
case 1:
printf("\nEnter the name of the customer here:\n ");
scanf("%s", &a -> name);
continue;
case 2: temp = 0;
printf("\n...EXITING PROGRAM...");
break;
}
}
return 0;
}
node *getnode(){
return (node *)malloc(sizeof(node));
}
Please sign in to leave a comment.