Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void PrinterFunction(void)
- {
- // both the alphabet and its size are constants. the size is reduced by
- // one to account for the terminating nullchar, which we do *NOT* want
- // as a viable choice of letters.
- static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- static const size_t alpha_size = sizeof alphabet/sizeof *alphabet - 1;
- // open the file
- FILE *fp = fopen("Default.txt", "a");
- if (fp == NULL)
- {
- perror("Defaults.txt : ");
- exit(EXIT_FAILURE);
- }
- // generate a two-character random selection from the alphabet characters
- char str[3] =
- {
- alphabet[rand() % alpha_size],
- alphabet[rand() % alpha_size],
- 0
- };
- // write to output, followed by newline
- fputs(str, fp);
- fputc('\n', fp);
- // close the file.
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement