Write a Modular C Programming Code for Sorting Strings | Sentence Ascending and Descending?
CODE:
#include<stdio.h> #include<string.h> void sort(char str[]); main() { char str[1000]; printf("Enter the word\n"); scanf("%s",str); sort(str); printf("\nWord after sorting each character = %s\n",str); } void sort(char str[]) { int i,j; char temp; for(i=0;str[i]!='\0';i++) { for(j=0;j<strlen(str)-1-i;j++) { if(str[j] > str[j+1]) { temp = str[j]; str[j] = str[j+1]; str[j+1]=temp; } } } }
OUTPUT
Enter the word qwertyuiopasdfghjklzxcvbnm Word after sorting each character = abcdefghijklmnopqrstuvwxyz Process returned 0 (0x0) execution time : 15.719 s Press any key to continue.
Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:
Top 100+ C Programming codes – KLE Technological University