As has already been said, Windows Notepad expects a carriage return-line feed pair (\r\n). There is, however, no other reason to stick to this out-dated method of ending a line (invented due to the slowness of the tele-type machine of the day) but you do need to know about it for reading text files since so many still use it.
If you want to see more accurately what is in the file you are writing, try something like
Notepad++[
^], which will interpret CR, LF, or a CRLF pair, as a new line, and you can also switch on display of these characters (and also all white space characters) from the menu (View->Show Symbol).
Out of interest, how come you are using the Windows API functions (CreateFile ...) to write the file, but the C functions (fopen ...) to read it? I'd stick with one or the other. If the app is being compiled for use only on Windows, go with the Windows API functions.
Thus you might open a file for reading like this:
HANDLE ApplicationfileOpenHandle = ::CreateFile(ApplicationFileLogName, FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
If insisting on using the fopen/fgets option, for VC++ at least consider using the more secure function
fopen_s[
^].
However, I note that you have a comment against your fgets line that the file is Unicode, but you don't appear to be reading it as if it is Unicode, nor converting correctly from whatever the Unicode encoding is into your multi-byte string. So this is another area you may need to look at.
The down-side of the Windows API functions is a there is no obvious function to read a line. This is my method (but again, this is
not for Unicode - you will have to work that one out yourself if you really need it):
std::string ReadLine
(
HANDLE theFile
)
{
if (INVALID_HANDLE_VALUE == theFile)
{
}
std::string result;
char readChar = 0;
const DWORD numberOfBytesToRead = sizeof(readChar);
DWORD numberOfBytesRead = 0;
do
{
BOOL readResult = ::ReadFile(theFile, &readChar,
numberOfBytesToRead, &numberOfBytesRead, NULL);
if (FALSE == readResult)
{
}
if (numberOfBytesRead > 0)
{
if (readChar == '\r')
{
}
else if (readChar == '\n')
{
break;
}
else
{
result += readChar;
}
}
} while(numberOfBytesRead > 0);
return result;
}
Regards,
Ian.