Advertisement
iKernel

isbn_gen.c

Nov 8th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define FILE_ISBNS "isbns.txt"
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     if(argc < 3)
  10.     {
  11.         printf("Modo de uso: %s <Cantidad de ISBNS> <Longitud ISBN>\n", argv[0]);
  12.         return 0;
  13.     }
  14.  
  15.     FILE *archivo_isbns;
  16.  
  17.     archivo_isbns = fopen(FILE_ISBNS, "w+");
  18.  
  19.     if (archivo_isbns == NULL)
  20.     {
  21.         perror("Error al crear archivo de ISBNS.\n");
  22.         return -1;
  23.     }
  24.  
  25.     for(int i=0; i<atoi(argv[1]); i++)
  26.       {
  27.             for(int x=0; x<atoi(argv[2]); x++) {fprintf(archivo_isbns, "%i", rand() % 10);}
  28.             fprintf(archivo_isbns, "\n");
  29.       }
  30.  
  31.     printf("\nHECHO!\n");
  32.     fclose(archivo_isbns);
  33.    
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement