Thread: Sentence count

  1. #1
    Registered User
    Join Date
    Feb 2010

    Sentence count

    Hi, I have an assignment which asks me to write several functions which count the number of words, syllables and sentences. I have managed to get the word and syl count, but I am not entirely sure how to go about counting sentences. I was thinking of reading a string and terminating after a period, colon, semicolon, question mark, or exclamation mark however i'm not sure how to go about it.

    This is my code so far.

    #include <stdio.h>
    #include <string.h>
    int wordcount( char words[]){
    char c;
    int num = 0;
    int space = 0;
    while(c = getchar() != '\n'){
      if(c==' '){
         space = 0;}
      else if(space == 0){
         num = num + 1;
         space = 1;}
    int sylcount( char * words )
     int i , j , sylc=0, length=strlen(words);
     char * vowels="AEIOUYaeiouy";
     for(j=0 ; j<=length ; j++)
            while( j<= length && strchr(vowels, words[j]) != 0 ) j++ ;
            if( 1<j-i ){ sylc++ ; i=j; }
    printf("%d\n", sylcount(argv[1]));
    int main(){

  2. #2
    Registered User
    Join Date
    Sep 2009

    just trying to figure out the array(words) does it mean that each index has a single sentence? or a single word?.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Well, it was meant to be for individual words, however looking at it now it seems as if it is sentences. Something i'll have to correct, thank you for bringing it to my attention.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Why can't you use the techniques you use for words and syllables for sentences?

    Also, ';' does not end a sentence.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Because I am not sure how to get it to read the last character at the end of the sentence . Also i know that semicolons don't end sentences, just as far as the assignment guidelines are concerned they do.

    I've come up with this so far.

    int sentencecount( char * sent)
     int i, j , sencnt = 0, len = strlen(sent);
     char *sentenders = ".;:?!";
     for(j=0; j<=len; j++);
         if(strchr(sentend, sent[j]))
    Last edited by mrkrinkle; 02-10-2010 at 01:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bintree and count (withouth using template)?
    By cubimongoloid in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2009, 06:22 AM
  2. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  3. Replies: 5
    Last Post: 09-28-2004, 12:38 PM
  4. How to count the words in sentence ?
    By Th3-SeA in forum C Programming
    Replies: 1
    Last Post: 10-01-2003, 01:34 AM
  5. 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