In this question, i want to store n names in a string array but it is only storing n-1 names. It is skipping the first iteration. It works perfectly when scanf is used. Why is it happening? I am a newbie in C . Please help me out!
#include<stdio.h>
int main()
{
int n=0;
puts("Enter the no. of names to be saved");
scanf("%d",&n);
char nm[n][20];
printf("Enter %d names\n",n);
for(int i=0;i<n;i++)
{
printf("%d.",(i+1));
gets(nm[i]);
}
return 0;
}