Saturday, 9 May 2009

Arrange the name in alphabetical order

Description:-
If u want to arrange ur name & others name in the alphabetical order then this is the program which will help u to do that job very well.

For example if u give the following names in the order:-
a)santanu
b)arnab
c)biswajit
d)sourav
e)joy
f)agni
The output will be:-

a)agni
b)arnab
c)biswajit
d)joy
e)santanu
f)sourav

-:Screen shots:-




Process:-
1. Copy the entire source code(Bold in format).
2. Paste that in your c or c++ compiler.
3. Save that with a suitable name.
4. Compile that program.
5. Finally run that program.

Error handling:-
Due to inappropiate html coding done by this web page I can't give the header file
name like stdio.h, conio.h, stdlib.h, iostream.h, fstream.h, iomanip.h etc.
If u get an error report after compiling the program
"CALL TO UNDEFINED FUNCTION 'PRINTF(OR ANYTHING)' IN FUNCTION MAIN()"
please add the above mentioned header file after #include
like #include.

Disclaimer:-
If you have any other problem regarding the program please mail me.
My mail address is showing on my blog page.


Source code:-

#include
#include
#include
void reorder(int n,char x[][12]);
main()
{
int i,n=0;
char x[100][12];
printf("Enter each name in a single line\n\n");
printf("Type 'end' when finished\n\n'");
do
{
printf("string %d: ",n+1);
scanf("%s",x[n]);
}
while(strcmp(x[n++],"end"));
n--;
reorder(n,x);
for(i=0;i printf("\nstring %d: %s",i+1,x[i]);
}
void reorder(int n,char x[][12])
{
char temp[12];
int i,item;
for(item=0;item {
for(i=item+1;i {
if(strcmp(x[item],x[i])>0)
{
strcpy(temp,x[item]);
strcpy(x[item],x[i]);
strcpy(x[i],temp);
}
}
}
return;
}

0 comments: