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