int main()
{
constint BUF_SIZE = 256;
constchar *originalFile = "TestFile1.txt"; //constant of original
constchar *toModify = "TestFile1_Modified.txt"; //modified version
constchar *findThis = "the"; //sequence to replace
constchar *replaceWith = "TT"; //sequence to replace with
char buf[BUF_SIZE]; //array
char *pointToBuf, *replacePnt; //two pointer to char to keep track
FILE *original = fopen(originalFile, "r"); //open file and assign to pointer
FILE *replacement = fopen(toModify, "w");
size_t toLength = strlen(findThis);
while(fgets(buf, BUF_SIZE, original)) //gets one line at a time
{
pointToBuf = buf; //Sets temp pointer to array
while ((replacePnt = strstr(pointToBuf, findThis))) //while pointer points to desired string
{
while (pointToBuf < replacePnt) //pointer less than the replacement pnt
fputc((int)*pointToBuf++, replacement); //move the pointer
fputs(replaceWith, replacement); //puts the replacement string in place
pointToBuf += toLength; //move pointer up pst changes
}
fputs(pointToBuf, replacement); //copys strings from original
}
fclose(original); //close both files
fclose(replacement);
return EXIT_SUCCESS;
}