When I entered the age input "20" hit Enter, it goes to a new line, hit Enter again, it goes to a new line again.
No matter how many time I hit enter it didn't get out of it until I typed "harri" or any char/words,then it get out of the code then display the next line of code. Why is that? How I can fix it so that when I type "20" Enter, then it will execute next line of code(printf(" Please enter your name\n")
)?
Output: output
void print_Struct_Element(List *list) {
printf("String name: %s\n",list->head->name);
printf("Age data: %d\n",list->head->age);
printf("head address %p\n",list->head );
printf("tail address %p\n",list->tail );
printf("head value %p\n",&list->head );
printf("tail value %p\n",&list->tail );
}
int main() {
char name[10];
int age, count;
printf("Please enter your age ");
scanf("%d\n",&age);
printf(" Please enter your name\n");
scanf("%s\n",name);
List moneyManagerList;
insertAtHead(&moneyManagerList,name,age );
print_Struct_Element(&moneyManagerList);
return 0;
}
And this is my other attempt; all fail:
int main() {
char name[10];
int age, count;
// printf("Please enter your name and age \n ");
// sscanf("harrison 30", "%s %d",name, &age );
printf("Please enter your age ");
//fgets(age, 5, stdin);
scanf("%d\n",&age);
printf(" Please enter your name\n");
fgets(name,10, stdin);
//scanf("%s\n",name);
List moneyManagerList;
insertAtHead(&moneyManagerList,name,age );
//moneyManagerList.head->name = strcpy(moneyManagerList.head->name, name );
//printf("head string name %s\n",moneyManagerList.head->name );
print_Struct_Element(&moneyManagerList);
return 0;
}
Github link:https://github.com/lambigini87/linked-link-moneyManager-project/blob/master/main.c