home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CONVCHAR.ZIP / CONVCHAR.C next >
C/C++ Source or Header  |  1989-06-12  |  2KB  |  41 lines

  1. /*    ConvChar.C - DOS filter to convert single characters to another char */
  2. /*    This little ditty is hereby released into public domain */
  3. /*    Author - Steve Kraus - 12 June 1989*/
  4.  
  5. #include <stdio.h>
  6.  
  7. void main (int argc, char *argv[])
  8.  
  9. {
  10.     int c;                /* char read from stdin & converted */
  11.     int fromch;            /* source char to convert */
  12.     int toch;            /* destination char to convert */
  13.  
  14.     if (argc < 2) {                    /* need two arguments, give help & quit */
  15.         fputs ("ConvChar is a DOS filter to convert single character values globally\n"
  16.             "  to another character value.  Usage:\n\n"
  17.             "ConvChar fromchar tochar <source >dest        Where:\n\n"
  18.             "  fromchar is the decimal value of the character to convert\n"
  19.             "  tochar   is the decimal value of the character to replace\n"
  20.             "  source   is the Ascii source file\n"
  21.             "  dest     is the Ascii destination file\n\n"
  22.             "ConvChar 0 255 <olddoc >newdoc\n"
  23.             "Reads & copies OLDDOC file to NEWDOC, converting chars valued 0 to value 255\n\n"
  24.             "ConvChar 255 0 <newdoc >newerdoc\n"
  25.             "Reverses above, reads NEWDOC, converts 255 value chars back to 0 on NEWERDOC\n\n"
  26.             "DIR /W | ConvChar 9 32\n"
  27.             "Converts all tab chars from DIR /W (value 9) to a single space (value 32)\n"
  28.             ,stdout);
  29.         exit(1);
  30.     }
  31.  
  32.     fromch = atoi (argv[1]);            /* source character value */
  33.     toch = atoi (argv[2]);                /* destination character value */
  34.  
  35.     while ((c = getchar()) != EOF) {    /* read single char until EOF */
  36.         if (c == fromch) c = toch;        /* convert matching characters */
  37.         putchar (c);                    /* copy character to stdout */
  38.     }
  39.  
  40. }
  41.