Input a string and change it is that the characters are placed in alphabetical order.
For example, the string "motivate" should be changed to "aeimottv"
Difficulty level
![](images/star2.png)
This exercise is mostly suitable for students
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define SIZE 100
void main()
{
char str[SIZE], aux;
int i, j, minpos;
printf("Enter a string : ");
gets(str);
for(i=0; str[i]!='\0';i++)
{
minpos=i;
for(j=i+1; str[j]!='\0';j++)
if(str[j]<str[minpos])
minpos=j;
if(minpos!=i)
{
aux=str[minpos];
str[minpos]=str[i];
str[i]=aux;
}
}
printf("In alphabetical order: %s\n",str);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
![](images/star3.png)