|
Eranga Thennakoon wrote: readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;
Taking the length of tempBuffer is wrong.
And my doubt is that, before you read, are you sure that the file is opened for read?
- NS -
|
|
|
|
|
No, I'm try to find the length of the string in buffer. strlen() gives it, right? I found it on MSDN. It gives the length of CString.
Actually file is open on previous click event.
I appreciate your help all the time...
Eranga
|
|
|
|
|
but here, unless you are reading your text from file, how are you able to get its length?
any way, you can see your inbox and see my mail, to which, you can forward it.
|
|
|
|
|
Eranga Thennakoon wrote: Actually file is open on previous click event.
After that you write the value? If so the file pointer is at the end of content, right? Then you have to reset it to initial position. In the case of CFile, you can use SeekToBegin API
- NS -
|
|
|
|
|
Yes it is true. But those comes later, isn't it? I mean need worried about those things when I use multiple lines of text. At the time I can read at least a single line pal.
That why I need your help.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I am not much clear about what you said. I think you have a file having multiple lines. So when you write a string then you think that the file pointer is not at the end of the file. Am I right?
- NS -
|
|
|
|
|
Actually you no need think in that much.
Right now just write a line of text and want to read it to a edit control and display. That's it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
sorry! for the delay Eranga
right now i'm called for a meeting.
i will get back by 5:30 pm
and guide u.
till then good luck!
i have some clue for u
in write button,
1.open the file in write mode,
2.write the data
3.close the file.
in read button,
1.open the file in read mode,
2.read the data
3.close the file.
|
|
|
|
|
Thanks for the tip. I'll work it on.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: write a line of text and want to read it
For this, I have said to use SeekToBegin. Hope it will work.
- NS -
|
|
|
|
|
Something like this.
<br />
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
TCHAR tempBuffer[256] ;<br />
UINT readText = 0;<br />
openFile.SeekToBegin();<br />
readText = openFile.Read(tempBuffer, 256 ) ;<br />
SetDlgItemText(IDC_S_READ, tempBuffer ) ;<br />
}<br />
This code given by Naveen.R and seems it is work. But one issue is there, can't read line of text more than 256 characters.
I appreciate your help all the time...
Eranga
|
|
|
|
|
You are reading only 256 at the maximum.
Eranga Thennakoon wrote: openFile.Read(tempBuffer, 256 ) ;
- NS -
|
|
|
|
|
Actually that what I'm try to change. Want to set it to the length of a line of test(a string).
I appreciate your help all the time...
Eranga
|
|
|
|
|
One solution can be as follows...
while( Not EOF file)
{
read the file.
add to a cstring.
}
set the cstring to edit control
- NS -
|
|
|
|
|
come on,
now initiate a loop, and read character by character and save them to an array.
or
i think, CFile returns you the nuymber of bytes in the file, so, read that many number of bytes. iam not sure but just try it.
|
|
|
|
|
I think it is possible using CFile::GetLength(). Wait, I'll test it now.
I appreciate your help all the time...
Eranga
|
|
|
|
|
|
forward me your application i shall see it.
|
|
|
|
|
Sure.
But how can I attach them. I can't see your mail address. If I past on the mail-body here in the forum it can be a real mess.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: void CSRFToolDlg::OnBnClickedRead()
{
char tempBuffer[256] ;
I think _UNICODE is defined your project so you are writing some wchar and trying to read some multi byte cahracters. try changing the following way
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
TCHAR tempBuffer[256] ;<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, 256 ) ;<br />
SetDlgItemText(IDC_S_READ, readText) ;<br />
}
|
|
|
|
|
I think the issue is on UINT. Is says that cannot convert parameters of SetDlgItemText() from 'UINT' to 'LPCTSTR'
I appreciate your help all the time...
Eranga
|
|
|
|
|
I just noticed you are trying to set the number of bytes returned by the read() function. If you want to set the read text change the readText with tempBuffer.
SetDlgItemText(IDC_S_READ, tempBuffer) ;
|
|
|
|
|
I want to print the text which is write to the file. No need to find the number of bytes. Initially I've tried this one also. What happened is print some annoying text on the edit control. It is true, because the buffer is size of 256 which I've defined.
I appreciate your help all the time...
Eranga
|
|
|
|
|
did u try after changing the char tempBuffer to TCHAR tempBuffer ?
|
|
|
|
|
Yes I've tried it.
<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;<br />
It's gives the error on above code. Gives an error on UINT and LPCTSTR. But I can't find any such conversions.
I appreciate your help all the time...
Eranga
|
|
|
|