I am reading text from a file and showing in an edit control. The file has multiple lines. But whenever a line ends, the edit control is showing a '|' symbol and then goes to the new line.
For example, if the content of the file is
First
Second
Third
The edit control shows
First|
Second|
Third
Note that, the edit control shows the pipe symbol, and then goes to a new line. I think that symbol represents either \n or \r which it couldn't show properly. But when I display the same text inside the loop using a MessageBox() function, I don't get the pipe symbol at the end each line.
Here is the relevent portion of my code:
TCHAR buffer[256];
TCHAR file[256] = L"C:\\Documents and Settings\\Dil\\Desktop\\Test.txt";
FILE* fp;
_wfopen_s(&fp, file, L"rt");
while(fgetws(buffer, sizeof(buffer), fp) != NULL)
{
int len = GetWindowTextLength(hDestEdit);
SendMessage(hDestEdit, EM_SETSEL, (WPARAM)len, (LPARAM)len);
SendMessage(hDestEdit, EM_REPLACESEL, 0, reinterpret_cast<LPARAM>(buffer));
}
fclose(fp);
Code used to create the edit control:
hDestEdit = CreateWindowEx(
WS_EX_CLIENTEDGE, L"EDIT", L"",
ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL|WS_TABSTOP|WS_VISIBLE|WS_CHILD,
100,100,400,300, hWnd, (HMENU)IDC_DEST_EDIT, GetModuleHandle(NULL), NULL);
How can I stop that weird character from showing up inside the edit control?
Edit
I checked using debugger. For each line that is read into buffer
, the final character before the null terminator is 0x000a - the line feed. The carriage return 0x000D is not present.
Edit 2
I tried the following code; the pipes are not there at end of each line, but I get 8 or 9 continuous pipes at the end of the last line. I am unable to inspect ndividual characters of buffer in the debugger.
TCHAR * buffer;
int length;
wifstream is;
is.open (file, ios::binary );
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
// allocate memory:
buffer = new TCHAR [length];
// read data as a block:
is.read (buffer,length);
is.close();
// send message to edit control
int len = GetWindowTextLength(hDestEdit);
SendMessage(hDestEdit, EM_SETSEL, (WPARAM)len, (LPARAM)len);
SendMessage(hDestEdit, EM_REPLACESEL, 0, reinterpret_cast<LPARAM>(buffer));