home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / MIDISTUF.ZIP / rec.cpp < prev   
C/C++ Source or Header  |  1995-01-01  |  3KB  |  84 lines

  1. /*  File  rec.cpp
  2.         by Dustin Caldwell   (dustin@gse.utah.edu)
  3. */
  4.  
  5. #include <dos.h>
  6. #include <stdio.h>
  7. #include <ctype.h>
  8. #include <stdlib.h>
  9.  
  10. void helpdoc();
  11.  
  12. main()
  13. {
  14.         FILE *rfp, *wfp;
  15.  
  16.         unsigned char ch, c;
  17.         char s[20];
  18.  
  19.         if((rfp=fopen(_argv[1], "r"))==NULL)                    /* open the read file */
  20.         {
  21.                 printf("cannot open file %s \n",_argv[1]);
  22.                 helpdoc();
  23.                 exit(-1);
  24.         }
  25.  
  26.         if((wfp=fopen(_argv[2], "wb"))==NULL)                   /* open the write file */
  27.         {
  28.                 printf("cannot open file %s \n",_argv[1]);
  29.                 helpdoc();
  30.                 exit(-1);
  31.         }
  32.  
  33.         c=0;
  34.  
  35.         ch=fgetc(rfp);
  36.  
  37.         while(!feof(rfp))                       /* loop for whole file */
  38.         {
  39.  
  40.                 if(isalnum(ch))                 /* only 'see' valid ascii chars */
  41.                 {
  42.                         c=0;
  43.                         while(isdigit(ch))      /* only use decimal digits (0-9) */
  44.                         {
  45.                                 s[c]=ch;        /* build a string containing the number */
  46.                                 c++;
  47.                                 ch=fgetc(rfp);
  48.                         }
  49.                         s[c]=NULL;                      /* must have NULL terminator */
  50.  
  51.                         fputc(atoi(s), wfp);/* write the binary equivalent to file */
  52.  
  53.                 }
  54.  
  55.                 ch=fgetc(rfp);                  /* loop until next number starts */
  56.  
  57.  
  58.         }
  59.  
  60.         fclose(rfp);                    /* close up */
  61.         fclose(wfp);
  62. }
  63.  
  64.  
  65. void helpdoc()          /* print help message */
  66. {
  67.         printf("\n   Text File Encoder\n\n");
  68.  
  69.         printf("\n Syntax:  rec text_file_name binary_file_name\n\n");
  70.  
  71.         printf("by Dustin Caldwell  (dustin@gse.utah.edu)\n\n");
  72.         printf("This is a program that reads an ascii tab-\n");
  73.         printf("delimited file and builds a binary file where\n");
  74.         printf("each byte of the binary file is one of the decimal\n");
  75.         printf("digits in the text file.\n");
  76.         printf(" eg:\n\n");
  77.         printf("c:\>rec son3.txt son3.mid\n\n");
  78.         printf("(This will create a file called son3.mid which is\n");
  79.         printf("a valid binary file)\n\n");
  80.         printf("(dec.exe may also be useful, as it decodes binary files)\n\n");
  81.         printf("Have Fun!!\n");
  82. }
  83.  
  84.