I am writing a C program which inputs string from a user sorts it alphabetical Order. I have two questions here.
When I input the strings from user in this way below no error occurs.
for(int i =0; i < 7; i++)
{
printf("Enter the name %d\n",i+1);
scanf("%s",&name[i][0]);
}
what does name[i][0] mean if
char name[7][10];
Why are we setting up the 2nd index here to 0 ,isn't the 2nd dimension the maximum length of string which our arrray can handle.
My second question is
For such type of array what does the string handling function takes &name[i][0] or &name[i]?
The code I have written so far gives me desired output however with lots of warning
#include<stdio.h>
#include<string.h>
int main() {
char name[7][10];
for (int i = 0; i < 7; i++) {
printf("Enter the name %d\n", i + 1);
scanf("%s", & name[i]);
strlwr( & name[i]);
}
//Sort in alphabetical order
for (int i = 0; i < 7; i++) {
for (int j = i + 1; j < 7; j++) {
if (strcmp( & name[i][0], & name[j][0]) > 0) {
char temp[10];
strcpy(temp, & name[i]);
strcpy(name[i], & name[j]);
strcpy(name[j], & temp);
}
}
}
printf("The names in alphabetical order is\n");
for (int i = 0; i < 7; i++) {
puts(name[i]);
}
}
The warnings are:
warning: passing argument 1 of 'strlwr' from incompatible pointer type [-Wincompatible-pointer-types]
98 | strlwr(&name[i]);
and similar for other functions as well.