Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is C. Please write it C. 1) Prompt the user to enter a string of their choo

ID: 3804212 • Letter: T

Question

This is C. Please write it C.

1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt)

Ex:


(2) Implement a PrintMenu() function, which has a string as a parameter, outputs a menu of user options for analyzing/editing the string, and returns the user's entered menu option. Each option is represented by a single character.

If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to call PrintMenu() until the user enters q to Quit. (3 pts)

Ex:


(3) Implement the GetNumOfNonWSCharacters() function. GetNumOfNonWSCharacters() has a constant string as a parameter and returns the number of characters in the string, excluding all whitespace. Hint: Using fgets() to read input will cause your string to have a newline character at the end. The newline character should not be counted by GetNumOfNonWSCharacters(). Call GetNumOfNonWSCharacters() in the PrintMenu() function. (4 pts)

Ex:


(4) Implement the GetNumOfWords() function. GetNumOfWords() has a constant string as a parameter and returns the number of words in the string. Hint: Words end when a space is reached except for the last word in a sentence. Call GetNumOfWords() in the PrintMenu() function. (3 pts)

Ex:


(5) Implement the FixCapitalization() function. FixCapitalization() has a string parameter and updates the string by replacing lowercase letters at the beginning of sentences with uppercase letters. FixCapitalization() DOES NOT output the string. Call FixCapitalization() in the PrintMenu() function, and then output the edited string. (3 pts)

Ex:


(6) Implement the ReplaceExclamation() function. ReplaceExclamation() has a string parameter and updates the string by replacing each '!' character in the string with a '.' character. ReplaceExclamation() DOES NOT output the string. Call ReplaceExclamation() in the PrintMenu() function, and then output the edited string. (3 pts)

Ex.


(7) Implement the ShortenSpace() function. ShortenSpace() has a string parameter and updates the string by replacing all sequences of 2 or more spaces with a single space. ShortenSpace() DOES NOT output the string. Call ShortenSpace() in the PrintMenu() function, and then output the edited string. (3 pt)

Ex:

Explanation / Answer

#include <stdio.h>
#include <ctype.h>
#define MAX 100 // here you can define max number as per your need

char PrintMenu(char s[]);
void GetNumOfNonWSCharacters(char word[]);
void GetNumOfWords(char word[]);
void FixCapitalization(char word[]);
void ReplaceExclamation(char word[]);

int main()
{
char text[MAX];
printf("Enter a sample text: ");
fgets(text,MAX,stdin);
printf("You entered: %s", text); // Solution 1 o To take string input and print
char option = 'a';
while(option != 'q')
option = PrintMenu(text);

return 0;
}

char PrintMenu(char word[]) // Solution 2: to display Menu
{
char ch;
do{
printf(" MENU ");
printf("c - Number of non-whitespace characters ");
printf("w - Number of words ");
printf("f - Fix capitalization ");
printf("r - Replace all !'s ");
printf("s - Shorten spaces ");
printf("q - Quit ");
  
printf(" Choose an option :");
scanf("%c", &ch);
  
switch(ch)
{
case 'c': GetNumOfNonWSCharacters(word);
break;
  
case 'w': GetNumOfWords(word);
break;
  
case 'f': printf("Edited text: %s ", FixCapitalization(word));
break;
  
case 'r': printf("Edited text: %s", ReplaceExclamation(word));
break;
  
case 's': break;
  
case 'q': return ch;
break;
}
  
} while(ch == 'c' || ch == 'w' || ch == 'f' || ch == 'r' || ch == 's' || ch == 'q');
  
return ch;
}

void GetNumOfNonWSCharacters(char word[]) // Solution 3 : to get White space char
{
int count =0 ,i =0;
for(i =0; word[i] != ' '; i++)
{
if(word[i] != ' ')
count++;
}
  
printf(" Number of non-whitespace characters : %d ", count);
}

void GetNumOfWords(char word[]) // solution 4 : to get number of words
{
int count =0 ,i =0;
for(i =0; word[i] != ' '; i++)
{
if(word[i] == ' ')
count++;
}
  
printf(" Number of words : %d ", count+1);
}

char [] FixCapitalization(char word[]) // Solution 5 to fix capitalization
{
int i =0;
  
for(i =0; word[i] !=' ';)
{
if(word[i] - 'a' >= 0 && word[i] - 'a' < 26)
{
word[i] = toupper(word[i]);
i++;
}
  
while(1)
{
if(word[i] != ' ' && word[i] != '.')
i++;
else
break;
}
if(word[i] != ' ') i++;
while(word[i] == ' ') i++;
}
  
return word;
}

char[] ReplaceExclamation(char word[]) //Solution 6 to Replace exclamation
{
int i=0;
  
for(i =0; word[i] != ' '; i++)
{
if(word[i] == '!')
word[i] = '.';
}
  
return word;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote