summaryrefslogtreecommitdiffstats
path: root/subs/subs.c
blob: 03f05c5cb8d1ff4db0d2298ce5a52d6868b575c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <strings.h>
#include <stdio.h>
#include <unistd.h>

void usage(char *name)
{
  fprintf(stderr,"Usage:\n\t%s [-n <character>] [-w <character>] <string>\n",name);
}

int main(int argc, char *argv[])
{
  char *h,n=':',w=' ';
  int c;

  while((c=getopt(argc, argv, "n:w:"))!=-1)
    switch(c)
    {
      case 'n':
        n=optarg[0];
        break;
      case 'w':
        w=optarg[0];
        break;
      default:
        usage(argv[0]);
        return 1;
    }

  if(optind>=argc)
  {
    usage(argv[0]);
    return 1;
  }

  h=argv[optind];
  while( (h=index(h, n)) !=NULL )
    *h++=w;
  
  printf("%s",argv[optind]);

  return 0;
}