F Program To Sort The List Of Person Alphabetically In C | CodeTheta

Program To Sort The List Of Person Alphabetically In C

December 20, 2015

/*Program To Sort The List Of Person Alphabetically*/
/* http://native-code.blogspot.com */
#include<stdio.h>
#include<conio.h>
#define PERSON 3
#define MAXCHAR 20
void main()
{
char string[PERSON][MAXCHAR],dummy[MAXCHAR];
int i=0,j=0;
clrscr();

/*This Section Will Teach How To Reading The List*/

printf("/* http://native-code.blogspot.com */");
printf("\n\n ENTER NAME OF %d PERSON...\n\n\n",PERSON);
while(i<PERSON)
scanf("%s",string[i++]);

/* http://native-code.blogspot.com */
/*This Section For Sorting Technique*/

for(i=1;i<PERSON;i++)
{
for(j=1;j<=PERSON-i;j++)
{
if(strcmp(string[j-1],string[j])>0)
{
/*Section For Exchange Of Content*/
strcpy(dummy,string[j-1]);
strcpy(string[j-1],string[j]);
strcpy(string[j],dummy);
}
}/*Inner Loop End Here*/
}/*OuterLoop End Here*/
/*Sorting End Here*/
printf("/* http://native-code.blogspot.com */");
printf("\n\n Alphabetically List............\n\n");
for(i=0;i<PERSON;i++)
printf("\t%s\t",string[i]);
getch();
}
/* http://native-code.blogspot.com */

IDE Used To Test This Code : Turbo C

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment