I am trying to count the number of words, lines, character, sentences. But I keep on messing up. I want to tell it to count the number of periods and make that a sentence, but I am having trouble.
Code:
[tag]#include <stdio.h>
int
main( void )
{
unsigned long nl = 0UL; /* #lines */
unsigned long nw = 0UL; /* #words */
unsigned long nc = 0UL; /* #chars */
unsigned long ns= 0UL; /* #sents*/
int c;
int inword = 0; /* true only when inside a word */
while ( (c = getchar()) != EOF )
{
++nc;
if ( c == '\n' )
{
++nl;
}
if ( c == ' ' || c == '\n' || c == '\t'
|| c == '\r' || c == '\v' || c == '\f' )
{
/* if whitespace, we're not inside a word */
inword = 0;
}
if (c= ".")
{
++ns;
}
else if ( !inword )
{
inword = 1;
++nw;
}
}
printf( "%lu lines, %lu words, %lu chars %lu sents\n", nl, nw, nc, ns );
return 0;
[/tag]