home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n05 / dqa0595.exe / UPCASE.C < prev   
C/C++ Source or Header  |  1995-05-01  |  1KB  |  45 lines

  1. /*
  2.  *  Trivial MS-DOS program that converts all the lowercase characters
  3.  *  in a text file to uppercase.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <malloc.h>
  8.  
  9. #define BUFFERSIZE  0x4000
  10.  
  11. main (int argc, char *argv[])
  12. {
  13.     FILE *file;
  14.     char *buffer;
  15.     int i, count;
  16.     char ch;
  17.  
  18.     if (argc == 1)
  19.         return 0;   /* Nothing to do */
  20.  
  21.     if ((buffer = malloc (BUFFERSIZE)) == NULL)
  22.         return -1;  /* Memory allocation failed */
  23.     
  24.     if ((file = fopen (argv[1], "r+b")) == NULL) {
  25.         free (buffer);
  26.         return -1;  /* File open failed */
  27.     }
  28.     
  29.     while ((count = fread (buffer, 1, BUFFERSIZE, file)) != 0) {
  30.         for (i=0; i<count; i++) {
  31.             ch = buffer[i];
  32.             if ((ch >= 0x61) && (ch <= 0x7A))
  33.                 buffer[i] -= 0x20;
  34.         }   
  35.         fseek (file, -((long) count), SEEK_CUR);
  36.         fwrite (buffer, 1, count, file);
  37.         fseek (file, 0, SEEK_CUR);
  38.     }
  39.  
  40.     fclose (file);  
  41.     free (buffer);
  42.     return 0;
  43. }
  44.  
  45.