Tuesday, April 7, 2015

NEWLINE in a c pgm

#include
#include

typedef int Bool;
const Bool TRUE = 1;
const Bool FALSE = 0;

const char SPACE = ' ';
const char NEWLINE = '\n';

void main ()
{
  ifstream f;
  char c;
  int numGaps;

  f.open("test.words");

  numGaps = 0;
  f.get(c);
  while (f)
 {
    if (c == NEWLINE)
 {
      numGaps = numGaps + 1;
      f.get(c);
    }
    else if (c == SPACE)
 {
      while (f && c == SPACE)
 {
f.get(c);
      }
      numGaps = numGaps + 1;
    }
    else f.get(c);
  }
  cout << "There are " << numGaps << " words" << endl;
}

No comments:

Post a Comment