Question

6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to...

6.17.1 Lab #5 - Chapter 6 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 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 '\t'. Call the OutputWithoutWhitespace() function in main(). (2 pts)

Ex:

(output) 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. (input) The only thing we have to fear is fear itself.

Write in C,with printf and scanf statements with loops.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int GetNumOfCharacters(char str[]){
    int i = 0;
    while(str[i]!='\0'){
        i++;
    }
    return i;
}

void OutputWithoutWhitespace(char str[]){
    int i = 0;
    while(str[i]!='\0'){
        if(str[i]!=' ' && str[i]!='\t'){
            printf("%c",str[i]);
        }
        i++;
    }
}

int main()
{
    char str[200];
    
    printf("Enter a sentence or phrase: ");
    scanf(" %[^\t\n]s",&str); 
    
    printf("You entered: %s\n",str);
    printf("Number of characters: %d\n",GetNumOfCharacters(str));
    printf("String with no whitespace: ");
    OutputWithoutWhitespace(str);

    return 0;
}
Add a comment
Know the answer?
Add Answer to:
6.17.1 Lab #5 - Chapter 6 Text analyzer & modifier (C) (1) Prompt the user to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Warm up: Text analyzer & modifier

    7.15 LAB: Warm up: Text analyzer & modifier(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 getNumOfCharacters() method, 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() method and then output the returned result. (1 pt)(4) Implement the outputWithoutWhitespace() method, which outputs the string's characters except for whitespace (spaces, tabs). Note: A tab...

  • This program should be run on Visual Studio. Please use printf and scanf as input and...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.11 Lab Exercise Ch.6a: Functions: String analyzer Create and debug this program in Visual Studio. Upload your Source.cpp file for testing (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: ics Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have...

  • C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need...

    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...

    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,...

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

    (1) Prompt the user to enter a string of their choosing. 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! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

  • Program: Authoring assistant

    7.17 LAB*: Program: Authoring assistant(1) Prompt the user to enter a string of their choosing. 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! You entered: 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() method, which 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() method....

  • C++ A Program for Examining String (1) Ask the customer to type any string they like...

    C++ A Program for Examining String (1) Ask the customer to type any string they like and then print it to the console. Example: Type a sentence: The CIS161 Computer Science II course is so much fun! You typed: The CIS161 Computer Science II course is so much fun! (2) Write the remaining code for the CountOfLetters() function, which returns the number of characters in the string that was entered. To get full credit for this question, this should be...

  • Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string"...

    Write in C Spring 2016 Lab Assignment 11 ET2100 In computer programming in general a "string" is a sequence of characters. In the C language anything within double quotes is a "string constant" so you have been seeing strings all semester. But we can also have string variables. In the C language these are implemented as an array of char, e.g. char name (10]: In order to make these variables easier to work with, it has been universally agreed that...

  • Need help with this homework, and follow the bolded text required 7.10 LAB: Data Visualization (1) Write a function, get_data_headers(), to prompt the user for a title, and column headers for a table....

    Need help with this homework, and follow the bolded text required 7.10 LAB: Data Visualization (1) Write a function, get_data_headers(), to prompt the user for a title, and column headers for a table. Return a list of three strings, and print the title, and column headers. (2 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Ex: Enter the column 1 header: Author name You entered: Author name Enter the column...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT