write a program to get a 2 d character array and arrange them in alphabetical order.

i've tried it,but its not getting compiled.
im jus a beginner.so, someone plz help me.
given below is my program....


struct st{

       char a[5][10];

int main()
    int i,j;
    char b[10];

                    printf("enter the name of the %d person :",i+1);

printf("the names after arranging in alphabetical order:\n\n");

                printf("the name of the %d person is %s\n",i+1,ppl.a[i]);

return 0;

If you want sorted strings, then you have to compare them as strings, not as individual char's. You can see the problem:

Abbey should sort out lower than Cathy, but when you are comparing the 'b' in the second letter of Abbey, with the 'a' in the second letter of Cathy, it won't.

You need to #include <string.h>, and then use strcmp(string1, string2).

If strcmp() returns > 0, then string1 is higher (greater) than string2. If strcmp() returns 0, the strings are equal, and if strcmp() returns < 0, then string1 < string2.

in pseudo code:

if((strcmp(string1, string2)) > 0) 
  string1 > string2 so make your swap code
  right in here
end if
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.