how to replace the data in the file?

I’ve created following code…

fPIn = fopen("BARCODE.txt", "r");
fPOut = fopen("final.txt", "w");

if(fPOut == NULL)
{
    printf("file can not openn");
}
else
{
    fgets(cBuffer,2000,fPIn);
    printf("%sn",cBuffer);
    char* cStart = strstr(cBuffer,"[");

    if(cStart)
    {
        *cStart++ = '';
        char* cEnd = strstr(cBuffer,"[");
        *cEnd = '';
        fPParse = fopen("parse.txt","r");
        fgets(line,200,fPParse);
        //replace data of cBuffer with line

        fwrite(cBuffer,2000,1,fPOut);
    }
    else
    {
        fwrite(cBuffer,2000,1,fPOut);
        fcloseall();
    }
}

But I’ve some issues with this

  1. I’m not able to read next line with fgets – it reads only first line from fPIn.
  2. After finding the specific char from input file how should I replace it with the data from other file (FPParse)?
  3. Finally, the modified data is to be saved to the output file. How can I do that?

Input file looks like this:

c0001
f260
L
D11
H30
R0000
C0040
1X1100000100010B300300003003
181100202900027Part No
181100202900097[PRTNUM]
1e5504002400030B
1X1100002300010L300003
191100202000030Quantity
191100202000080[QUANTY]
1e5504001500040B
1X1100001400010L300003
1X1100001400150L003090
191100202000170P.O.No
191100202000220[PONUMB]
1e5504001500180Bsupplier
1e3304000700030B
1X1100000600010L300003
181100200300030Serial
181100200300090[SERIAL]
171100300900190Rev
171100300300190[REV]
171100300900240Units
171100300300240[UNITS]
1X1100000100180L003130
Q0001
E

second file (fPParse)

132424235
004342
L1000
DZ12
234235
234235


Source: c#

Leave a Reply