home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 193_01 / makef.c < prev    next >
Text File  |  1985-11-14  |  2KB  |  74 lines

  1. /*    
  2. ** makef.c    File Generator Program        by F.A.Scacchitti 10/7/85
  3. **
  4. **        Written in Small-C Version 2.10 or later
  5. **
  6. **        Creates a seqential file of characters from
  7. **        0 to 255 in blocks of 255 bytes.
  8. **        The sequential characters can be replaced
  9. **        with any single character desired.
  10. */
  11.  
  12. #include <stdio.h>
  13.  
  14. #define BUFSIZE 256
  15.  
  16.  
  17. int fdout;        /* file  i/o channel pointers */
  18. int i, n, num;
  19. char *outbuf, value; 
  20.  
  21. main(argc,argv) int argc, argv[]; {
  22.  
  23. /*
  24. ** Allocate memory for buffer
  25. */
  26.  
  27.    outbuf = malloc(BUFSIZE);
  28.  
  29. /*
  30. ** Check arguments passed and open file stream
  31. */
  32.    if(argc < 3) {
  33.       printf("\nmakef usage: makef <new file> <nnnn> [ddd]\n");
  34.       printf("             nnnn = file size in 256 byte blocks\n");
  35.       printf("             ddd  = optional alternate value in decimal\n");
  36.       exit();
  37.    }
  38.    if((fdout = fopen(argv[1],"w")) == NULL) {
  39.       printf("\nUnable to create %s\n", argv[1]);
  40.       exit();
  41.    }
  42. /*
  43. ** Convert file size argument to integer
  44. */
  45.    if((n = atoi(argv[2])) == NULL) exit();
  46.  
  47. /*
  48. ** Fill the buffer with 0 to 255 sequence
  49. */
  50.    for(i = 0; i <=255; i++)
  51.       outbuf[i] = i;
  52.  
  53. /*
  54. ** Refill the buffer with a single character if directed by argument
  55. */
  56.    if(argc == 4)
  57.       if((value = atoi(argv[3])) < 256)
  58.          for(i = 0; i <=255; i++)
  59.             outbuf[i] = value;
  60.  
  61. /*
  62. ** Write blocks to file
  63. */
  64.    for(i=1; i <= n; i++)
  65.       if((num = write(fdout,outbuf,BUFSIZE)) < BUFSIZE) exit();
  66.  
  67. /*
  68. ** Close up shop
  69. */
  70.  
  71.    fclose(fdout);
  72. }
  73.  
  74.