Program to count number of words from a given sentence

The below mentioned C Program will count number of words from a given sentence. The program will accept a sentence in a character array sen[100]. It will then calculate the number of words and display the result.

Also See:
Strings in C Programming Language

You may also like...

11 Responses

  1. Anonymous says:

    Doesn’t work there is a syntax error stating that it is missing ‘;’ before ‘)on line 12.

  2. Anonymous says:

    for (i=0;i

    and count=1

  3. Anonymous says:

    u hve entr a erong entry… that is getch()

  4. Anonymous says:

    It work’s

  5. Anonymous says:

    what if there is ‘,'(comma) symbol in the given sentence??

  6. Anonymous says:

    this does not work for sentence having multiple spaces between two words

  7. Anonymous says:

    very good work , although there are some mistake .

    I correct it and here is the new code :


    using namespace std;

    int main()
    char sen[100];
    int i, count = 0;

    printf(“Enter a Sentence : \n”);

    for (i=0; i {
    if (isspace(sen[i]))

    printf(“Number of words in the sentence = %d”, ++count);



  8. Reshma K C says:

    can anyone do the same code using pointers??

  9. Anonymous says:

    what if I give the input as –
    Hello I am there.

    ur ouput will be wrong..

  10. DEEPAK THOMAS says:

    what if there are 3 spaces before each word ???? each time it wil count the spaces as words ryt ???? how is it possible?

Leave a Reply

Your email address will not be published. Required fields are marked *