nocturnalmk

lab8-4

Dec 20th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void promena(FILE *p, FILE *n, char x, char y) {
  5.  
  6.     int c;
  7.  
  8.     if (p == NULL || n == NULL) {
  9.         printf("Datotekata ne postoi.\n");
  10.     } else {
  11.  
  12.          while(c != EOF) {
  13.  
  14.             c = fgetc(p);
  15.  
  16.             if (c != EOF) {
  17.                 if (c != x) {
  18.                     fputc(c, n);
  19.                 } else {
  20.                     if (c == x) {
  21.                         fputc(y, n);
  22.                     }
  23.                 }
  24.             }
  25.  
  26.         }
  27.  
  28.     }
  29.  
  30. }
  31.  
  32. int main(int argc, char *argv[]) {
  33.     FILE *p;
  34.     FILE *n;
  35.     char x,y;
  36.  
  37.     printf("\n\nargc = %d\n\n", argc);
  38.  
  39.     x = argv[3][0];
  40.     y = argv[4][0];
  41.     printf("Ke se zamenat %c so %c\n\n", x, y);
  42.  
  43.     p = fopen(argv[1], "r");
  44.     n = fopen(argv[2], "w");
  45.  
  46.     promena(p, n, x, y);
  47.  
  48.     fclose(p);
  49.     fclose(n);
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment