In C code ( UNIX C CODE), please, do not do it in another language Text analyzer
ID: 3857541 • Letter: I
Question
In C code ( UNIX C CODE), please, do not do it in another language
Text analyzer & modifier (C)
--
(1) Prompt the user to enter a string of their choosing. Output the string. (1 pt)
(2) 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. (2 pts)
(3) In main(), call the GetNumOfCharacters() function and then output the returned result. (1 pt)
(4) Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is ' '. Call the OutputWithoutWhitespace() function in main(). (2 pts)
Ex:
Explanation / Answer
#include <stdio.h>
int GetNumOfCharacters(char s[]) {
int count = 0;
int i;
for(i=0; s[i]!='';i++) {
count++;
}
return count;
}
void OutputWithoutWhitespace(char s[]) {
int i;
printf("String with no whitespace: ");
for(i=0; s[i]!='';i++) {
if(s[i]!=' '&& s[i]!=' ') {
printf("%c",s[i]);
}
}
printf(" ");
}
int main()
{
char s[1000];
printf("Enter a sentence or phrase: ");
gets(s);
printf("You entered: %s ", s);
printf("Number of characters: %d ", GetNumOfCharacters(s));
OutputWithoutWhitespace(s);
return 0;
}
Output:
sh-4.2$ main
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.