C Code
Create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the “quit” command.
The commands are:
• “Replace All” If a user types “replace all” using ANY sort of capitalization, your program will prompt the user to enter the character to change and the new character. Afterward, it will replace all instances of the first character with the new character and will printout the new string. This method does change the original sentence entered.
• “Quit” – If the user types “quit” with any sort of capitalization, the program will stop running.
Note: Examples of capitalizations to consider are ALL CAPS, all lowercase, or mIxED CapITAlIzAtIon.
For this, you need to make sure your program can gracefully handle user errors. That is, simply stating “An error occurred” does not help a user recover from a mistake. Specific errors your program should be capable of fixing (not a complete list) are:
• If the user enters a character that does not exist within the string, your program should display an error and prompt them for the next command.
• Case matters within the run of each command. If a user requests that the letter ‘q’ get replaced, your program should not replace any capital ‘Q’ letters.
• If the user enters an invalid command, you should display an error message and ask for a valid command.
Write a program called string_manipulator.c that accomplishes the requirements listed earlier in this assignment. Additional program specifications include:
• Your main should not manipulate any strings or do any tasks aside from gathering user input, and calling functions as needed.
• Your program should include a function called replaceAll that replaces all characters in the input string with the desired new character. This is the only place where any sort of string manipulation should occur. You are responsible for writing the complete declaration and implementation of this function. You can choose to implement this function above your main, or afterward with a declaration above the main. This function can take any parameters you deem appropriate.
• Once the program starts, all error messages should display helpful messages and then re-prompt the user with the choices (as shown in the sample run through).
• Your output formatting should mimic the sample output provided in this document. Do not add extra spacing or change the wording.
Enter a string (up to 25 characters) to be transformed: Go Tigers
Enter your command (quit, replace all): REPLACE ALL
Enter the character to replace: e
Enter the new character: 3
Your new sentence is: Go Tig3rs
Enter your command (quit, replace all): replace some aaaaaaaaaaaaa12341234
Sorry, that command is invalid. Please type one of the options.
Enter your command (quit, replace all): replace all
Enter the character to replace: i
Enter the new character: 1
Your new sentence is: Go T1g3rs
Enter your command (quit, replace all): rePLace ALL
Enter the character to replace: q
Error, q is not in the string.
Enter your command (quit, replace all): QUIT
Code
#include<stdio.h>
#include<string.h>
#include <ctype.h>
void replaceAll(char str[], char to, char with)
{
int i = 0;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] == to)
{
str[i] =
with;
}
}
printf("Your new sentence is: %s\n",str);
}
int findChar(char str[],char ch)
{
int i,flag=0;
for (i = 0; str[i] != '\0'; i++)
{
if (str[i] ==ch)
{
return 1;
}
}
return 0;
}
int main()
{
char str[25];
char command[100];
int i = 0;
char charToReplace, charWithReplace;
printf("Enter a string (up to 25 characters) to be
transformed:");
scanf("%[^\n]%*c", str);
while(1)
{
while (1)
{
fflush(stdin);
printf("Enter
your command (quit, replace all):");
scanf("%[^\n]%*c", command);
for (i = 0;
command[i] != '\0'; i++)
{
command[i] = tolower(command[i]);
}
if
(strcmp(command, "replace all") == 0 || strcmp(command, "quit") ==
0)
{
break;
}
else
{
printf("Sorry, that command is invalid. Please
type one of the options.\n");
}
}
fflush(stdin);
if (strcmp(command, "replace
all")==0)
{
printf("Enter
the character to replace:");
scanf("%c",
&charToReplace);
if(findChar(str,charToReplace)==1)
{
fflush(stdin);
printf("Enter the new character: ");
scanf("%c", &charWithReplace);
replaceAll(str, charToReplace,
charWithReplace);
}
else
printf("Error, %c is not in the string.\n",
charToReplace);
}
if (strcmp(command,
"quit")==0)
{
break;
}
}
return 0;
}
output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank you.
C Code Create a tool in which a user can enter a string (up to 25...
Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.
complete the code The instructions to a turtle can be encoded in a string. Complete Asn4_5 as follows: In main() the user will be prompted to enter instructions to a turtle as follows. The instructions will be entered in a loop that will end when the user enters quit or Quit at the first prompt. The first prompt will ask for a color. If the user enters quit or the user enters Quit the program will exit. The second prompt...
Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...
complete the code The instructions to a turtle can be encoded in a string. Complete Asn4_5 as follows: In main() the user will be prompted to enter instructions to a turtle as follows. The instructions will be entered in a loop that will end when the user enters quit or Quit at the first prompt. The first prompt will ask for a color. If the user enters quit or the user enters Quit the program will exit. The second prompt...
C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...
C++ please! (1) Prompt the user to enter the name of the input file. The file will contain a text on a single line. Store the text in a string. Output the string. Ex: Enter file name: input1.txt File content: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! (2) Implement a PrintMenu() function,...
Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...
14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...
Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...
Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...