2D Array sorting. This is a very easy program. Here we used strcmp() to compare the strings with in an array of string.
#include<string.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
char names[5][30],temp[30];
printf("Enter 5 Names\n");
for(i=0;i<5;i++)
{
gets(names[i]);
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(names[i],names[j])>0)
{
strcpy(temp,names[i]);
strcpy(names[i],names[j]);
strcpy(names[j],temp);
}
}
}
printf("\n\n OUTPUTS \n\n");
for(i=0;i<5;i++)
{
puts(names[i]);
}
}