Hi all;
If i have the following:
Code:
typedef struct {
char firstname[10];
char surname[10];
int age;
}database;
and i want to take in values for firstname and surname and age like this:
Code:
for(int i=0; i<5;i++)
{
fgets(ptr[i]->firstname, sizeof(ptr[i]->firstname), stdin);
printf("\nEnter the surname");
fgets(ptr[i]->surname, sizeof(ptr[i]->surname), stdin);
printf("Enter the age");
scanf("%d",&ptr[i]->age);
}
There is some code above missing, ie mallocs etc.
The scanf causes the firstname to be skip on the next round of the loop.
What can i use instead of scanf to solve the problem, i know its to with scanf not taking spaces, so firstname takes the space and thats why its blank
Any ideas?
Thanks