In C programming 7.18 Ch 7 Warm up: Text analyzer & modifier (C) (1) Prompt the
ID: 3908577 • Letter: I
Question
In C programming
7.18 Ch 7 Warm up: Text analyzer & modifier (C) (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself You entered: The only thing we have to fear is fear itself. (2) Complete the GetNumOfCharacters0 function, which returns the number of characters in the user's string. We encourage you to use a for loop in this function. (2 pts) (3) In main0, call the GetNumOfCharacters0 function and then output the returned result. (1 pt) (4) Implement the OutputWithoutWhitespace0 function. OutputWithoutWhitespace0 outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is ' . Call the OutputWithoutWhitespace0 function in main. (2 pts) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself Number of characters: 46 String with no whitespace: Theonlythingwehavetofearisfearitself. LAB ACTIVITY 7.18.1: Ch 7 Warm up: Text analyzer & modifier (C) 0/6 main.c Load default template... 1 #include 2 #include 4 //Returns the number of characters in usrStr 5 int GetNumOfCharacters(const char usrStr|) I 7*Type your code here. * 10 11 int main(void) T 12 Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Develop mode Submit mode Enter program input (optional)Explanation / Answer
#include <iostream>
using namespace std;
int GetNumOfCharacters(const char usrStr[])
{
int count = 0;
int i = 0;
for (i = 0; usrStr[i] != ''; i++)
count++;
return count;
}
void OutputWithoutWhitespace(const char usrStr[])
{
cout << "String with no whitespace: ";
int i = 0;
for (i = 0; usrStr[i]; i++)
if (usrStr[i] != ' ' && usrStr[i] != ' ')
cout << (char)usrStr[i];
}
int main(void)
{
char usrStr[100];
char ch;
int i = 0;
cout << "Enter a sentence or phrase: ";
while ((ch = getchar()) != ' ') //read until newline
usrStr[i++] = ch;
usrStr[i] = '';
cout << " You entered: " << usrStr << " ";
cout << "Number of characters: " << GetNumOfCharacters(usrStr) << endl;
OutputWithoutWhitespace(usrStr);
return 0;
}