Dear programmers,
I have this problem in getting a user's input. I'll try to explain may problem as good as i can:
- I'm using the struct to store some data:
Code:
typedef struct restaurant {
char name[NAMESIZE];
char email[EMAILSIZE];
char type[TYPESIZE];
}Restaurant;
- Then, fill this struct I ask the user to write some data, with this:
Code:
//Insert Name
add_text("Name",&r,r->name,sizeof(r->name));
//Insert e-mail
add_text("e-Mail",&r,r->email,sizeof(r->email));
//Insert restaurant type
add_text("Type",&r,r->type,sizeof(r->type));
- The add_text function is:
Code:
int add_text(const char* field, Restaurant** res, char* data, int size)
{
printf("%s: ", field);
fflush(stdout);
if (fgets(data, size, stdin) == NULL)
{
printf("\n<No data found!>\n");
free(*res);
return 1;
}
clean_string(data);
return 0;
}
So the problem is with the fgets functions. The first time I use this last function my program seems to jump to the next add_text() function. So the result is:
(prompt)
"Name: e-Mail: kovitch@gmail
Type: none"
As you see it jumps somehow, and i don't have the opportunity to write the name down.
What could be the problem here? I'd be very greatfull if somebody could help me out.
Regards