I'm building an Address Book to store an individuals name, address and phone number. I'm having trouble with the append function.
struct node{
char name[21];
char address[101];
char phone[15];
struct node *next;
};
void append(){
if(root == NULL){ // Empty list
struct node *temp = (struct node*) malloc(sizeof(struct node));
printf("Enter Name: ");
fgets(temp->name,20,stdin);
printf("Enter Address: ");
fgets(temp->address,100,stdin);
printf("Enter Phone Number: ");
scanf("%s",&temp->phone);
}
}
For the name and address I except the user to enter a string with whitespaces so I decided to use fgets(). However, I'm not sure how to store the name or address the user enters into the node. When I run my program fgets() is not called for the name, instead it jumps to the address and then asks the user to enter a phone number.