C program to sort character array (string) in ascending order
Below is the simple C program that will accept the character string from the user, calculates the length of the string and performs sorting operation on the string. The program will sort the character array in ascending order and display the result string (character array).
Here we go,
#include<stdio.h> #include<conio.h> void main() { clrscr(); int i,j; char *arr; //accept character array string from user printf("Enter character string: "); gets(arr); //get the length of array in the variable counter int counter = 0; while(arr[counter] != NULL){ counter = counter + 1; } //apply ascending sorting algorithm for(i=0; i<counter; i++) { for(j=i; j<counter;j++) { if (arr[i] > arr[j]) { char arrtemp; arrtemp = arr[i]; arr[i] = arr[j]; arr[j] = arrtemp; } } } //display the final result for(i=0;i<counter; i++) { printf("%c", arr[i]); } getch(); }
C Programming is brought you by LearnCOnline.com
What could be the code snippet that processes a String, and replaces every 5th character
with
Thank you for posting your query. We have worked on your question and have the code ready.
Please visit the below link for the solution.
https://www.learnconline.com/2015/05/c-program-to-read-a-string-and-replaces-every-5th-character-with-x.html
Learn C in just 6 days… Visit http://www.aptuts.com
can i install turbo c++ on windows 7 without using DosBox emulator
Instead of using Turbo C++, you can try MS visual studio to write and run C/C++ programs.
write a C program to calculate the count, total, and then average of marks above 60 in the array marks.
write a c program to sort a list of string according to the length of the string in descending order using a two dimensional array. The program will continue accepting string until and unless