I have this code.
#include <stdio.h>
struct name
{
int age;
char fullname[20];
};
struct name names[20];
int main()
{
int n,i;
printf("Count of names:\n");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("Name %d : ",i);
scanf("%[^\n]s",names[i].fullname);
}
return 0;
}
And when i execute :
rupam@linux ~ $ ./a.out
Count of names:
5
Name 0 : Name 1 : Name 2 : Name 3 : Name 4 :
rupam@linux ~ $
It don't wait for user input. Somehow the scanf is not working.
Well, if i use
scanf("%s",names[i].fullname);
It works for single word inputs. What am i doing wrong here ?
[^\n].sfor the format string?%[^\n]sworked.scanf(" %[^\n]",names[i].fullname);: Because newline remaining(ofscanf("%d",&n);,).