Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void PrinterFunction(void)
  6. {
  7.     // both the alphabet and its size are constants. the size is reduced by
  8.     //  one to account for the terminating nullchar, which we do *NOT* want
  9.     //  as a viable choice of letters.
  10.     static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  11.     static const size_t alpha_size = sizeof alphabet/sizeof *alphabet - 1;
  12.    
  13.     // open the file
  14.     FILE *fp = fopen("Default.txt", "a");
  15.     if (fp == NULL)
  16.     {
  17.         perror("Defaults.txt : ");
  18.         exit(EXIT_FAILURE);
  19.     }
  20.  
  21.     // generate a two-character random selection from the alphabet characters
  22.     char str[3] =
  23.     {
  24.         alphabet[rand() % alpha_size],
  25.         alphabet[rand() % alpha_size],
  26.         0
  27.     };
  28.    
  29.     // write to output, followed by newline
  30.     fputs(str, fp);
  31.     fputc('\n', fp);
  32.    
  33.     // close the file.
  34.     fclose(fp);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement