home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / pclcjs.zip / CHARS.C < prev    next >
C/C++ Source or Header  |  1993-06-12  |  3KB  |  147 lines

  1. #include <ctype.h>
  2. #include <string.h>
  3.  
  4. /* repchar function Copyright 1992 by Chuck Steenburgh
  5.  
  6.    This function will replace all instances of a given character
  7.    in a string with another
  8.    
  9.    repchar accepts the following arguments:
  10.    
  11.    char *s - string in which character(s) are to be replaced
  12.    char c  - character to be replaced
  13.    char r  - replacement character
  14.    
  15.    Returns:  number of characters replaced
  16.                                                                          */
  17.                                                                        
  18.  
  19. int repchar(char *s, char c, char r)
  20.     
  21. {
  22.     /* local variable */
  23.     int counter=0;
  24.     
  25.     while (s = strchr(s,c)) {
  26.         *s = r;
  27.         counter++;
  28.     }
  29.     
  30.     return counter;
  31. }
  32.  
  33.  
  34.  
  35. /* remchar function Copyright 1993 by Chuck Steenburgh 
  36.  
  37.    This function will remove all instances of a given character
  38.    in a string and NOT replace it
  39.    
  40.    repchar accepts the following arguments:
  41.    
  42.    char *s - string from which character(s) are to be removed
  43.    char c  - character which is to be deleted
  44.    
  45.    Returns: number of characters removed                                 */
  46.  
  47.  
  48. int remchar(char *s, char c)
  49.     
  50. {
  51.     /* local variable */
  52.     int counter=0, count, count2;
  53.     
  54.     for (count=0;count<strlen(s);count++) {
  55.         
  56.         if (s[count]==c) {
  57.             
  58.             for (count2=count;count2<strlen(s);count2++) 
  59.                 s[count2]=s[count2+1];
  60.             
  61.             counter++;
  62.         }
  63.     }
  64.     
  65.     return counter;
  66. }
  67.  
  68.  
  69. void remove_chars(char *in_line)
  70.  
  71. {
  72.     /* Local variables */
  73.     int counter2, counter3=0;
  74.     char *out_line;
  75.  
  76.     for (counter2=0;counter2<strlen(in_line);counter2++) {
  77.         if (isdigit(in_line[counter2])) {
  78.             out_line[counter3++]=in_line[counter2];
  79.         }
  80.     }
  81.     out_line[counter3++]='\n';
  82.     strcpy(in_line,out_line);
  83. }
  84.  
  85.     
  86.     
  87. void remove_digits(char *in_line)
  88.  
  89. {
  90.     /* Local variables */
  91.     int counter2, counter3=0;
  92.     char *out_line;
  93.  
  94.     for (counter2=0;counter2<strlen(in_line);counter2++) {
  95.         if (isprint(in_line[counter2])) {
  96.             if (isdigit(in_line[counter2]) == 0)
  97.                 out_line[counter3++]=in_line[counter2];
  98.         }
  99.     }
  100.     out_line[counter3++]='\n';
  101.     strcpy(in_line,out_line);
  102. }
  103.  
  104.  
  105.  
  106. void epsonize(char *s, int c)
  107.  
  108. {
  109.     /* Local variables */
  110.     int counter4;
  111.     
  112.     /* Check each character and replace as necessary */
  113.     for (counter4=0;counter4<strlen(s);counter4++) {
  114.         
  115.         if (s[counter4] > 127) {
  116.                     
  117.             switch(s[counter4]) {
  118.                         
  119.                 case 179: case 186:
  120.                     s[counter4] = 124;
  121.                 break;
  122.                 case 180: case 181: case 182: case 185: case 193: 
  123.                 case 194: case 195: case 197: case 198: case 199: 
  124.                 case 202: case 203: case 204: case 206: case 207: 
  125.                 case 208: case 209: case 210: case 215: case 216:
  126.                     s[counter4] = 43;
  127.                 break;
  128.                 case 183: case 184: case 187: case 188: case 189: 
  129.                 case 190: case 191: case 192: case 200: case 201: 
  130.                 case 211: case 212: case 213: case 214: case 217: 
  131.                 case 218:
  132.                     s[counter4] = 42;
  133.                 break;
  134.                 case 196: case 205:
  135.                     s[counter4] = 45;
  136.                 break;
  137.                 case 219: case 220: case 221: case 222: case 223:
  138.                     s[counter4] = 88;
  139.                 break;
  140.                 default:
  141.                     s[counter4]=c;
  142.                 break;
  143.             }
  144.         }
  145.     }
  146. }
  147.