C Programming

Sorting a String

Program to Sort a given String in C.

Language : C

[sourcecode language='c']
#include
#include
void main()
{
char a[]={“NEHA”};
int b[100],j,t,l,i;
i=0;

l=strlen(a);
printf(“%d”, l);
while(i {
b[i]=a[i];
i++;
}

for(i=0;i {
for(j=0;j {
if(b[j]>b[j+1])
{
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}

}
}
j=0;
while(j {
a[j]=b[j];
j++;
}
printf(“\nSorted String : %s”,a);

}
[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal