in a C program I want to append data to a text file. Used the fopen function like this:
FILE* fileLog;
char logFile_name[] = "C:\\pg\\log.txt";
fileLog = fopen(logFile_name, "r+");
int j = 0;
while (j < 4)
{
fprintf(fileLog, "%u,%s", GetLastError(), "1_aba_1\n");
j++;
}
GetLastError sometimes returns (ok), but the file is overwritten and not added.
Used the fopen function like this:
FILE* fileLog;
char logFile_name[] = "C:\\pg\\log.txt";
fileLog = fopen(logFile_name, "a+");
std::cout << GetLastError() << " LOG \n";
int j = 0;
while (j < 3)
{
fprintf(fileLog, "%u,%s", GetLastError(), "56_aba_4\n");
j++;
}
Data is added but GetLastErrorgives an error 183. Programm continues work correctly in both cases, but i use this code in postgre extension, and it crashes and lose connection server for unknown reasons. How to correctly add data to a file without error?
from Microsoft System Error Codes:
ERROR_ALREADY_EXISTS 183 (0xB7). Cannot create a file when that file already exists
I think that this is just a reminder that the file is already there.