All pastes #945930 Raw Edit

Something

public text v1 · immutable
·published 2008-03-17 09:09 UTC
rendered paste body
#include <stdio.h>
#include <stdbool.h>

#define out false
#define in true

/*Print the number of words, characters and new lines...*/
int main (void)
{
     bool state = out;
     int chars, lines, words, c;
     chars = words =lines = 0;

     while ((c = getchar ()) !=EOF)
          {
               ++ chars;
               if ( c == '\n')
                    {
                    ++ lines;
               state = out;
                    }
               else if (c == ' ')
                                                                 state = out;
               else if (c == '\t')
                                         state = out;
               else if (!state)
                    {
                         state =in;
                         ++ words;
                    }
          }
     /* print the values...*/
     printf ("Words %d, New lines %d, Characters %d\n", words, lines, chars);
     return 0;
}