Please, C code 6.18 Ch 6 Warm up: Text analyzer & modifier (C) Prompt the user t
ID: 3857386 • Letter: P
Question
Please, C code
6.18 Ch 6 Warm up: Text analyzer & modifier (C)
Prompt the user to enter a string of their choosing. Output the string. 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. Complete the GetNumOfCharacters() function which returns the number of characters in the user's string. We encourage you to use a for loop in this function. In main(), call the GetNumOfCharacters() function and then output the returned result. Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). 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.Explanation / Answer
#include<stdio.h>
#include<conio.h>
/*Function to print the number of characters in the string including the whitespaces*/
int GetNumofCharacters(char string[])
{
int i, string_length = 0;
for(i = 0; string[i] != ''; i++)
if(string[i] == ' ') /*Including the whitespace as a character*/
string_length++; /*Incrementing the string length*/
else
string_length++;
return string_length; /*Returning the number of characters in the string*/
}
/*Function to print all the characters without white spaces*/
void OutputWithoutWhitespace(char string[])
{
int i;
printf("String with no whitespace: ");
for(i = 0; string[i] != ''; i++)
if(string[i] != ' ') /*Checking whether the character is a whitespace or not*/
printf("%c", string[i]); /*Printing each character*/
}
/*Main Function*/
void main()
{
char sentence[10000];
printf("Enter a sentence or phrase ");
gets(sentence); /*Reading the input from console using gets*/
printf(" You entered: %s ", sentence); /*Printing the input entered by the user*/
printf(" Number of characters: %d ", GetNumofCharacters(sentence)); /*First Function that is called*/
OutputWithoutWhitespace(sentence); /*Second Function that is called*/
}