Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- /* generate a text file with random combinations of 4 characters
- from a, b, c, d on each line */
- /* created for testing performance here: http://askubuntu.com/a/339182/67132 */
- /* compilation: make rndgen1 */
- /* detailed compilation: make rndgen1 CC=gcc CFLAGS="-W -Wall -pedantic" */
- #define NLINES 200000000 /* number of output lines */
- #define CHPLINE 4 /* characters per line */
- #define PROGNAME "rndgen1" /* program name */
- #define NPOSIB 4 /* output character possibilities */
- #define FCHAR 'a' /* first output character possibility */
- void errexit(const char *msg)
- {
- fprintf(stderr, "%s: %s\n", PROGNAME, msg);
- exit(EXIT_FAILURE);
- }
- int main(int argc, char *argv[])
- {
- int i, j;
- FILE *fout;
- if(argc < 2) errexit("Too little arguments - You must specify an output file.");
- if((fout = fopen(argv[1], "w")) == NULL) errexit("Error opening output file");
- srand(time(NULL));
- for(i = 0; i < NLINES; i++) {
- for(j = 0; j < CHPLINE; j++) {
- if(putc(FCHAR + rand() % NPOSIB, fout) == EOF) {
- errexit("Error writting to file.");
- }
- }
- if(putc('\n', fout) == EOF) errexit("Error writting to file.");
- }
- fclose(fout);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement