Question

Write a program that counts the number of characters and words in the following statement: This...

Write a program that counts the number of characters and words in the following statement:

This is a long exercise. I would like to get done with it. END

            Hint: In order to count words, count the transitions from non-white space to white space characters

Please use C Language and complete program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <string.h>
int main()
{
    char str[200];
    int i,j = 0, count = 0, len;
    printf("Enter word: ");
    scanf("%[^\n]s",str); 
    
    len = strlen(str);
    
    for(i=0;i<=len;i++)
    {
        if(str[i]==' '||str[i]=='\0')
        {
            count++;
        }
    }
    printf("count = %d\n",count);
    return 0;
}

Enter word: test string to test program count = 5 Process exited after 2.515 seconds with returnvalue 0 Press any key to cont

Add a comment
Know the answer?
Add Answer to:
Write a program that counts the number of characters and words in the following statement: This...
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
  • 12.13 (Count characters, words, and lines in a file) Write a program that will count the...

    12.13 (Count characters, words, and lines in a file) Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in Figure 12.13 D Command Prompt exercise java Exercise12.13 Loan.java ile Loan.jaua has 1919 characters 10 words 71 lines lexercise Figure 12.13 The program displays the number of characters, words, and lines in the given file. This...

  • c program that counts the number of characters, words and lines from standard input until EOF....

    c program that counts the number of characters, words and lines from standard input until EOF. attached is what i Have so far but its not working ?. about shell redirection Requirements 1. Write a C program that counts the number of characters, words and lines read from standard Input until EOF Is reached. 2. Assume the Input is ASCII text of any length. 3. Every byte read from stdin counts as a character except EOF 4. Words are defined...

  • Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words...

    Word count. A common utility on Unix/Linux systems. This program counts the number of lines, words (strings of characters separated by blanks or new lines), and characters in a file (not including blank spaces between words). Write your own version of this program. You will need to create a text file with a number of lines/sentences. The program should accept a filename (of your text file) from the user and then print three numbers: The count of lines/sentences The count...

  • In the language c using the isspace() function: Write a program to count the number of...

    In the language c using the isspace() function: Write a program to count the number of words, lines, and characters in its input. A word is any sequence of non-white-space characters. Have your program continue until end-of-file. Make sure that your program works for the case of several white space characters in a row. The character count should also include white space characters. Run your program using the following three sets of input:             1. You're traveling through ​               another...

  • The program reads an unknown number of words – strings that all 20 characters or less...

    The program reads an unknown number of words – strings that all 20 characters or less in length. It simply counts the number of words read. The end of input is signaled when the user enters control-d (end-of-file). Your program prints the number of words that the user entered. ****** How do you I make it stop when control-d is entered. My code: #include <stdio.h> void main(void) { char sentence[100]; int i = 0; int count = 1; printf("Enter a...

  • Write a program that reads a string entered at the command line and counts the number...

    Write a program that reads a string entered at the command line and counts the number of characters or words. A blank space should be used to delimit a word. Name the program StringCount and design it to be invoked using syntax as follows: StringCount –[c][w] user_string

  • Write a C++ console application that reverses an array of characters, and counts the number of:...

    Write a C++ console application that reverses an array of characters, and counts the number of:           Lower case characters (islower)           Upper case characters (isupper)           Digits (isdigit)           Other (not one of previous) Create four global variables to hold these counts. Create function void count(char input[], char reverse[]) that takes as input two arrays: one that contains characters and another that will contain the reverse of that array. The function will reverse the input array and do the...

  • C program: Write a program that assigns and counts the number of each alphabetic character in...

    C program: Write a program that assigns and counts the number of each alphabetic character in the Declaration of Independence and sorts the counts from the most used to the least used character. Consider upper and lower case letters the same. The frequency of each character should be accumulated in an array. USE POINTERS to increment counts for each letter, sort your array, and display the results. Output should consist of two columns: (1) each letter 'a'-'z' and (2) the...

  • Write a program in java to read a string object consisting 300 characters or more using...

    Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters.(Use String class methods). a, Determine the length of the string count the number of letters in the strings , count the number of numeric object d. Calculate the number of special character e. Compute the ratio of the numeric to the total f....

  • c++ Exercise #2: Words Count Write a program that prompts the user to enter a sentence,...

    c++ Exercise #2: Words Count Write a program that prompts the user to enter a sentence, then counts and prints the number of words in the sentence. Assume that there is more than one space between words of the sentence. Sample input/output: Enter a sentence: This is a 123test in There are 5 words in " This is a 123test \n"

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