Friday, 23 September 2016

Sort array of 10 strings

/* Sort array of 10 strings. */

#include<string.h>
#include<stdio.h>

int main()
{
int i,j;
char str[10][10],temp[10];
printf("Type 10 names :\n");
for(i=0;i<10;i++)
{
// gets(str[i]);
// fgets is a better option over gets to read multiword string .
fgets(str[i], 10, stdin);
}
for(i=0;i<10;i++)
{
for(j=0;j<10-1-i;j++)
{
if(strcmpi(str[j],str[j+1])>0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],temp);
}
}
}

printf("\nSorted Names :\n");
for(i=0;i<10;i++)
puts(str[i]);
return 0;
}

No comments:

Post a Comment

Featured post

Will AI Replace Programmers? The Truth Behind the Hype in 2025

Exploring the Future of Coding: Will AI Take Over Software Development or Enhance It?  Will AI Replace Programmers? The Truth Behind the Hyp...