- Open the file in read-only mode using the following code:
fp = fopen (argv [1],"r");
- If the file does not exist or does not have enough permissions, an error message will be displayed and the program will terminate, as shown in the following code:
if (fp == NULL) { printf("%s file does not exist\n", argv[1]); exit(1); }
- Enter the word to be replaced using the following code:
printf("Enter a string to be replaced: ");scanf("%s", str1);
- Enter the new word that will replace the old word using the following code:
printf("Enter the new string ");scanf("%s", str2);
- Read a line from the file using the following code:
fgets(line, 255, fp);
- Check whether the word to be replaced appears anywhere in the line using the following ...