The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sub.c File Reference
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for sub.c:

Go to the source code of this file.

Functions

 main (int argc, char **argv)
 

Function Documentation

main ( int  argc,
char **  argv 
)

Definition at line 29 of file sub.c.

30 {
31  FILE *fp;
32  char *buf;
33  int size;
34 
35  if ((argc < 3) || (argc > 4)) {
36  fprintf(stderr, "usage: %s <string> <substitute string> [filename]\n", *argv);
37  exit(-1);
38  }
39 
40  if (argc > 3)
41  fp = fopen(argv[3], "r");
42  else fp = stdin;
43 
44  size = strlen(argv[1]);
45  buf = (char *)calloc(size + 1, 1);
46 
47  while ((buf[size - 1] = fgetc(fp)) != EOF) {
48  if (!strcmp(buf, argv[1])) {
49  printf("\n%s", argv[2]);
50  memset(buf, 0, size);
51  continue;
52  }
53  if (*buf) {
54  printf("%c", *buf);
55  }
56  memmove(buf, &buf[1], size);
57  }
58  buf[size - 1] = 0;
59  printf("%s", buf);
60 }
int fp
Definition: gbfidx.cpp:49
int size
Definition: regex.c:5043