In this tutorial we will learn writing the C Program to sort the characters of String in ascending order. There are multiple sorting algorithms to sort the characters or integers. In this tutorial we will follow the insertion sorting algorithm to compare and sort the characters of the string.
You can check insertion sort program in c.
C Program to sort characters of string in ascending order
#include <stdio.h> #include <string.h> int main () { char str[100]; char temp; int i, j,len; printf("C Program to sort character in string\n"); printf("Please enter the string : "); scanf("%[^\n]",str); len = strlen(str); for (i = 0; i < len-1; i++) { for (j = i+1; j < len; j++) { if (str[i] > str[j]) { temp = str[i]; str[i] = str[j]; str[j] = temp; } } } printf("After sorting the character in ascending : %s", str); return 0; }
Output

Also Prepare Below Important Question
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
- Python Program to Delete element at End of Array
- Python Program to Copy one String to Another String
- Python Program to Remove Repeated Character from String
- Print highest frequency Character in String in Python
- Python Program to Convert lowercase vowel to uppercase
- Convert Celsius to Fahrenheit in Python
- Leap Year Program in Python
- Python Program to convert Decimal to Octal number
- Python Program to Convert Decimal Number into Binary
- Find all Pairs Whose Sum is Equal to Given number in Python
- Python Program to Replace First Vowel With ‘-‘ in String
- Python Program to find Prime factors of given integer
- Python Program to Print Prime Number in given range
- Java Program to Perform Left Rotation on Array Elements by Two
- Java Program to Perform Right Rotation on Array Elements by Two
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions