Win32 SDK 초보
WriteFile()를 사용할때 줄바꾸기(행바꾸기)
띠리
2007. 4. 12. 18:35
The Stupidity of Newlines
In the ASCII table above, there are two bytes that could legitimately be treated as indicating "this line of text is over. start a new one.":- 0x0A, '\n', Line Feed. This is the standard C way to indicate a new line is starting.
- 0x0D, '\r', Carriage Return. This actually moves the cursor back to the start of the line.
Sadly, every major computer system nowdays treats newlines differently.
In DOS/Windows, '\r' only moves the cursor horizontally to the start of the line, and '\n' only moves the cursor vertically down. This means to really start a new line of text in a DOS/Windows file, you need to use "\ \ ", like this:
------------------------------------------------------------------------
BOOL WriteLine(CString csLog)
{
DWORD dwLength;
CString csPrint;
BOOL fRet;
csrint.Format("%s\r\n", csLog);
fRet = WriteFile(hLog ,(LPCVOID)csPrint, csPrint.GetLength(), &dwLength, NULL);
return fRet;
}
------------------------------------------------------------------------
위에 소스의 빨강 부분처럼 써주어야지만
줄이 바뀌어 파일에 씌어지는군요.