Advertisement
sp1d3o

Untitled

Oct 21st, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1.  1 #include<stdio.h>
  2.   2 #include<string.h>
  3.   3 #include<stdlib.h>
  4.   4 #include<stdbool.h>
  5.   5 #include<errno.h>
  6.   6
  7.   7 extern int errno;
  8.   8
  9.   9 int main(int argc, char *argv[])
  10.  10 {
  11.  11         if(argc != 2) {
  12.  12                 fprintf(stderr, "Invalid input\n");
  13.  13                 exit(1);
  14.  14         }
  15.  15
  16.  16         FILE* fp;
  17.  17
  18.  18         char *orig = "func";
  19.  19         char *new = "printf";
  20.  20         char *ch;
  21.  21
  22.  22         int i;
  23.  23
  24.  24         fp = fopen("code_to_change.c", "r+");
  25.  25                 if(fp = NULL) {
  26.  26                         fprintf(stderr, "Cannot open file\n");
  27.  27                         exit(1);
  28.  28                 }
  29.  29                 else if(errno != 0) {
  30.  30                         fprintf(stderr, "Unexpected error\n");
  31.  31                         exit(1);
  32.  32                 }
  33.  33                 else {
  34.  34                         return 0;
  35.  35                 }
  36.  36
  37.  37         while((i = fgetc(fp)) != EOF) {
  38.  38                 if(ch == orig) {
  39.  39                         strcpy(orig, new);
  40.  40                 }
  41.  41         }
  42.  42         fclose(fp);
  43.  43
  44.  44         return 0;
  45.  45
  46.  46 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement