Tranfer to c++

Hello,
I am having a huge problem trying to transfer this to c++.
I guess your not supposed to use fgets or fopen with c++.

can anyone help me please.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main()
{
    const int BUF_SIZE = 256;
    const char *originalFile = "TestFile1.txt";             //constant of original
    const char *toModify = "TestFile1_Modified.txt";        //modified version
    const char *findThis = "the";                           //sequence to replace
    const char *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;
}


I guess your not supposed to use fgets or fopen with c++.

You can do it just fine.
┬┐What's the problem?
If your problem is that it doesn't compile, maybe you forgot to #include <cstdlib> , maybe?
It really helps if you tell us what the problem is.
Topic archived. No new replies allowed.