Question

In: Computer Science

Create program which sorts letters of a string based on ASCII value. The program will then...

Create program which sorts letters of a string based on ASCII value. The program will then print the sorted string to stdout. Use C programming language.

- Only use stdio.h

- Input prompt should say "Enter string of your choice: "

- Remove any newline \n from input string

- Implement sorting operation as a function. Should use selection sort algorithm, but you may use a different algorithm

- Output should print sorted string on new line

Example:

    Enter string of your choice: Vex'ahlia

    'Vaaehilx

   

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<stdio.h>


void selectionSort(char* s){
   int i, j;
   char temp;
   int min_index;
   for(i=0; s[i]!='\0'; i++){
      min_index = i;
      for(j=i+1; s[j]!='\0'; j++){
          if(s[min_index]>s[j]){
              min_index = j;
           }
       }
       temp = s[i];
       s[i] = s[min_index];
       s[min_index] = temp;
     
   }
  
  
}

int main(){
  
   char word[101];
  
   printf("Enter string of your choice: ");
   scanf("%s",word);
  
   selectionSort(word);
   printf("%s", word);

   return 0;
}

=================================================================


Related Solutions

Give pseudocode for a recursive function that sorts all letters in a string. For example, the...
Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy". Java
Give pseudocode for a recursive function that sorts all letters in a string. For example, the...
Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy". Python
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. ‘+’ and ‘-’ will appear optionally. And once they appear, they will only appear once in the first byte. If a non-digit character appears in the string, your program should stop and return -1.
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
The ASCII lowercase letters are separated from the uppercase letters by 32. Thus, to convert a...
The ASCII lowercase letters are separated from the uppercase letters by 32. Thus, to convert a lowercase letter to uppercase, subtract 32 from it. Use this information to write a program that reads characters from the keyboard. Have it convert all lowercase letters to uppercase, and all uppercase letters to lowercase, displaying the result. Make no changes to any other character. Have the program stop when the user enters a period. At the end, have the program display the number...
Create a program that accepts in a string of 2 or more words. The program then...
Create a program that accepts in a string of 2 or more words. The program then copies the entered string changing the alpha characters into digits representing characters with acsenders, descenders and nonascender/desender characters; uppercase characters should be treated as lower case. The characters with descenders (gjpqy) should be replaced with a 1. The characters with ascenders (dbfhklt) should be replaced with a 2. The rest of the alpha characters should be replaced with a 3. The converted string should...
Create program which verifies if input string is a valid variable declaration or not. Use C...
Create program which verifies if input string is a valid variable declaration or not. Use C programming language. - This program can only use the following variable types: char, float, and int - Remove any newline \n from input string - The input prompt should say ">>> " - If input declaration is valid, it should print "Valid dec\n" - If input declaration is invalid, it should print "Invalid dec\n" - Make sure the identifier entered matches the rules of...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
Write a program that sorts prices of 10 tacos in ascending order based on the price,...
Write a program that sorts prices of 10 tacos in ascending order based on the price, using arrays. Requirements: The user enters the name of the taco and then the price of the taco HINT: Two arrays make this problem simpler. One with the names and the other with the prices. The indices indicate the combination. For instance, a taco price at index 5 has its name also at index 5 of the other array. HINT: It is a good...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT