//=============================================== file = genAsciiFile.c ===== //= Program to generate file full of random ASCII "words" = //=========================================================================== //= Notes: = //= 1) Writes to a user specified output file = //= 2) Generates random ASCII words of a desired mean size (uniformly = //= distributed) = //= 3) File size is usually a few bytes larger then specified due to = //= the last word spilling over just a little = //=-------------------------------------------------------------------------= //= Example execution: = //= = //= c:\work>genAsciiFile = //= ----------------------------------- genAsciiFile.c ----- = //= - Program to generate a file with random ASCII words - = //= - of a (roughly) specified size. WARNING: Make sure - = //= - there is enough disk space available for the file. - = //= -------------------------------------------------------- = //= Output file name ===================================> out.txt = //= Specify mean word size (in characters) =============> 14 = //= Specify approximate file size (in bytes) ===========> 1000 = //= -------------------------------------------------------- = //= - Generating file - = //= -------------------------------------------------------- = //= -------------------------------------------------------- = //= - Done! - = //= -------------------------------------------------------- = //=-------------------------------------------------------------------------= //= Build: gcc genAsciifile.c, bcc32 genAsciiFile.c, cl genAsciiFile.c = //=-------------------------------------------------------------------------= //= Execute: genAsciiFile = //=-------------------------------------------------------------------------= //= Author: Ken Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~zreynold = //= Email: christen@csee.usf.edu = //=-------------------------------------------------------------------------= //= History: KJC (03/18/09) - Genesis = //=========================================================================== //----- Include files ------------------------------------------------------- #include // Needed for printf(), scanf(), and f*() #include // Needed for atoi() and rand() //===== Main program ======================================================== void main(void) { FILE *fp; // File pointer to output file char file_name[256]; // Output file name string int file_size; // File size specified by user int word_size; // Mean word size int ws; // Word size int count; // Byte counter char c; // Random character char temp_string[256]; // Temporary string variable int i; // Loop counter // Output banner printf("----------------------------------- genAsciiFile.c ----- \n"); printf("- Program to generate a file with random ASCII words - \n"); printf("- of a (roughly) specified size. WARNING: Make sure -\n"); printf("- there is enough disk space available for the file. - \n"); printf("-------------------------------------------------------- \n"); // Prompt for output filename and then create the file (write binary) printf("Output file name ===================================> "); scanf("%s", file_name); fp = fopen(file_name, "wb"); if (fp == NULL) { printf("ERROR in creating output file (%s) \n", file_name); exit(1); } // Prompt desired mean word size printf("Specify mean word size (in characters) =============> "); scanf("%s", temp_string); word_size = atoi(temp_string); // Prompt (rough) file size printf("Specify approximate file size (in bytes) ===========> "); scanf("%s", temp_string); file_size = atoi(temp_string); //Output message and generate file printf("-------------------------------------------------------- \n"); printf("- Generating file - \n"); printf("-------------------------------------------------------- \n"); // Generate file count = 0; while(1) { // Generate a word size ws = (rand() % word_size) + 1; // Create and write the work for (i=0; i= file_size) break; } // Output message and close the output file printf("-------------------------------------------------------- \n"); printf("- Done! - \n"); printf("-------------------------------------------------------- \n"); fclose(fp); }