I have seen other similar question but none of them solved my problem.
char name[30][15];
int i, n, found=0;
printf("Enter how many names you want to enter:");
scanf("%d", &n);
printf("Enter names of %d friends:", n);
for (i=0; i<n; i++)
scanf("%s", name[i]);
printf("Names are: ");
for (i=0; i<n; i++)
printf("%s\n", name[i]);
If I run this code, its runs properly but how can we input 1-D array when the array we defined is 2-D. Is the no of columns defined by default if we use name[i].
if I modify this code, it shows error.--
char name[30][15];
int i, n, found=0;
printf("Enter how many names you want to enter:");
scanf("%d", &n);
printf("Enter names of %d friends:", n);
for (i=0; i<n; i++)
scanf("%s", name[i][15]);
printf("Names are: ");
for (i=0; i<n; i++)
printf("%s\n", name[i]);
The output is--
Enter how many names you want to enter:2
Enter names of 2 friends:vyom
Names are:
forloops. It makes the code easy to read and less bug-prone. And keep indentation consistent - it doesn't make sense to further nestprintfat all given that it should probably be at the outermost indentation.