How it works...
Open the chosen file in read-only mode. If the file opens successfully, then the file pointer, fp, will be set to point at it. Enter the word to be replaced and assign it to the string variable, str1. Similarly, enter the new string that will be assigned to another string variable, str2. The length of the two strings, str1 and str2, will be computed and assigned to the variables, ls1 and ls2, respectively.
Set a while loop to execute until the file pointed at by fp pointer gets over. Within the while loop, one line from the file will be read using the fgets function. The fgets function reads the file until the maximum length that is specified or the new line character, \n, is reached, whichever comes first. Because strings ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access