Thread: how to count the number of sentences.

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Unhappy how to count the number of sentences.

    hi there

    i would really appreciate some help here. i am trying to count the number of sentences in a paragraph.By doing this i count the number of fullstops and then that is equavilent to the number of sentences. I think i got the idea but i can't get the program to work ....please help
    this is what i got:

    #include <stdio.h>
    #define max_char 100

    main(){
    char para[max_char];
    int len_sent,i,;

    printf("Please enter a paragraph\n");
    fflush(stdin);
    gets(para);

    len_sent = strlen(para);
    for(i=0;i<len_sen;i++){
    if(para[i]=='.'){
    printf("the number of sentences are: %d)<--I NEED HELP HERE TO COUNT THE NUMBER of FULLSTOPS(.)
    }


    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Exclamation thanks ..but i'n still not that clear

    hi thanks 4 th efast reply.
    i really appreciate it
    but i'm still not getting what i want
    please see what is wrong in this
    Code:
    #include <stdio.h>
    #define max_char 100
    
    main(){
     char para[max_char];
     int len_sent,i,count;
    
    printf("Please enter a paragraph\n");
    fflush(stdin);
    gets(para);
    
    len_sent = strlen(para);
      for(i=0;i<len_sent;i++){
        if(para[i]=='.'){
            count++;
        }
    }
    printf("the number of sentences are: %d\n", count );
    
    
    }

    and is fgets better to use than gets?


    Code Tags added by Kermi3

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    Code Tags

    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.


    Good Luck with your program,

    Kermi3
    Lead Moderator
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Talking THANKS!!!

    THANK YOU VERY VERY MUCH!...it finally worked...enjoy the rest of ur day and take cae
    THANKS AGAIn
    bye

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  3. prompting user for data
    By radical in forum C Programming
    Replies: 5
    Last Post: 07-28-2005, 11:45 AM
  4. Count the number of letter "a" on a sentence
    By imbecile in C in forum C Programming
    Replies: 6
    Last Post: 07-27-2003, 02:32 PM
  5. how to count sentences and words?
    By Ray Thompson in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 01:42 PM