C Programming Code Examples C > Strings Code Examples C Program to Sort the list of Strings C Program to Sort the list of Strings Write a C program which will accept multiple strings fron the user and will sort them in ascending order. We are checking each successive strings using strcmp() function. If string is greater than the successive string then we are swapping the strings. #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char *str[5], *temp; int x, j, n; printf("\nHow many names do you want to have?"); scanf("%d", &n); for (x = 0; x < n; x++) { printf("\nEnter the name %d: ", x); flushall(); gets(str[x]); } for (x = 0; x < n; x++) { for (j = 0; j < n - 1; j++) { if (strcmp(str[j], str[j + 1]) > 0) { strcpy(temp, str[j]); strcpy(str[j], str[j + 1]); strcpy(str[j + 1], temp); } } } flushall(); printf("\nSorted List : "); for (x = 0; x < n; x++) puts(str[x]); return (0); }