jeudi 19 février 2015

Writing a word count program in C


Vote count:

0




In this program a word is defined by any sequence of characters that does not include a "-" " " "\n" ":" "\t" So howdy-hi:slig would be three words in this program.


Increment


while ( ( iochar = getchar() ) != EOF ) {



if (iochar == '\n')
{
line++;
word++;
}

if (iochar == ':' || iochar == '-' || iochar == '\t' || iochar == ' ')
{
word++;
}


Instead of incrementing word everytime a whitespace is encountered I know I need to skip all the extra white space characters that can separate two words.


So that "hello - my : name is Earl." counts 5 words instead of 8.


Thank you appreciate it.



asked 38 secs ago







Writing a word count program in C

Aucun commentaire:

Enregistrer un commentaire