home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / 9n06106b < prev    next >
Text File  |  1990-12-12  |  1KB  |  45 lines

  1.  
  2.  
  3. //textgen.cpp
  4. //creates random ASCII text files for testing purposes
  5.  
  6. #include <stdio.h>
  7. #include <stream.hpp>
  8. #include <stdlib.h>
  9.  
  10. main()
  11. {
  12.    char ch, filename[13];
  13.    int p, q = 0, nblanks = 0;
  14.    unsigned long i, j = 1, nchar;
  15.  
  16.    cout << "Type name for testfile\n";
  17.    cin >> filename;
  18.    cout << "Type number of characters including whitespace\n";
  19.    cin >> nchar;
  20.  
  21.    char *text = new char[nchar-1];
  22.    if (!text) cout << "Out of heap memory\n";
  23.    filebuf file1;
  24.    file1.open(filename,output);
  25.    ostream output_file(&file1);
  26.  
  27.    for (i = 0; i < nchar; i++){
  28.       p = 33 + (94.0 * rand() / 32768.0);   
  29.                       //generate random numbers between 33 and 126
  30.       if (i == j){               //create words 1-10 chars long
  31.          p = 32;                             
  32.          q = 1 + (11.0 * rand() / 32768.0);
  33.          j = j + q;
  34.          ++nblanks; 
  35.          }
  36.       text[i] = p;
  37.       cout << text[i];
  38.       output_file << text[i];
  39.       }
  40.    cout << "\n" << "nblanks = " << nblanks;
  41.    delete text;
  42. }
  43.  
  44.  
  45.