Alphabetical Order C Program?
I have made an array of strings. The Objective is to print them in Alphabetical order. My Code is given below .... Please help me ... I am not getting an output. #include <stdio.h> #include <string.h> int main() { char Name_Array[][10] = {"avinash", "sushil", "alok", "prateek", "prashanth", "naveen"}; int i, j, x; char t[10]; for (i=0; i<7; i++) { for (i=0, j=1; i<5, j<6; i++, j++) { x = strcmp(&Name_Array[i][0], &Name_Array[j][0]); if (x>0) { strcpy(t, &Name_Array[i][0]); strcpy(&Name_Array[i][0], &Name_Array[j][0]); strcpy(&Name_Array[j][0], t); } } } for (i=0; i<6; i++) { printf ("%s ", &Name_Array[i][0]); } printf(" "); return 0; }
TELL US , if you have any answer