//---------------------------------------------------------------------------

#include <vcl.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <String>
#include <stdlib.h>

using namespace std;

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
  String filenaam = "gpl.txt";
  ifstream invoer(filenaam.c_str());
  if (invoer.fail()) {
    cout << "bestand niet gevonden";
    cin.get();
    return 1;
  }
  string word;

  ofstream uitvoer("tekst.txt");

  bool klinker = false;
  bool found = false;
  int wordlength = 0;
  int sentence = 0;
  while (!invoer.eof()) {
    invoer >> word;
    for (int x = 0; x < word.length(); x++) {
      if (word[x] > 64 && word[x] < 91) {
        word[x] += 32;
      }
    }
    found = false;
    if (klinker) {
      for (int x = 0; x < word.length(); x++) {
        if (!found) {
          if (word[x] == 'a' ||
              word[x] == 'e' ||
              word[x] == 'i' ||
              word[x] == 'o' ||
              word[x] == 'y' ||
              word[x] == 'u') {
            uitvoer << word[x];
            found = true;
            klinker = false;
            wordlength +=1;
          }
        }
      }
    } else {
      for (int x = 0; x < word.length(); x++) {
        if (!found) {
          if (word[x] != 'a' &&
              word[x] != 'e' &&
              word[x] != 'i' &&
              word[x] != 'o' &&
              word[x] != 'y' &&
              word[x] != 'u' &&
              word[x] > 96   &&
              word[x] < 123) {
            uitvoer << word[x];
            found = true;
            klinker = true;
            wordlength += 1;
          }
        }
      }
    }
    for (int x = 0; x < word.length(); x++) {
      if (word[x] == '.' ||
          word[x] == ',' ||
          word[x] == ';' ||
          word[x] == ':') {
        uitvoer << " ";
        wordlength = 0;
        sentence += 1;
      }
    }
    if (wordlength - 2 > random(12)) {
      if (sentence - 2 > random(20)) {
        uitvoer << ". ";
        sentence = 0;
      } else {
        if (random(20) < 1) {
          uitvoer << ",";
        }
        uitvoer << " ";
        sentence += 1;
      }
      wordlength = 0;
    }



  }
  uitvoer.close();
  cin.get();
  return 0;
}
//---------------------------------------------------------------------------
