coldest
asked on
How can I open and read a text file!!!!!!
Im using Palm-size pc 2.01
Why it crashes in the file.open line????? what am I doing wrong????
CString fname=(_T("mysetce.txt"));
CStdioFile file;
if (file.Open(fname,
CFile::shareExclusive | CFile::modeRead | CFile::typeText ) )
{
file.Read(st,50);
file.Close();
}
Why it crashes in the file.open line????? what am I doing wrong????
CString fname=(_T("mysetce.txt"));
CStdioFile file;
if (file.Open(fname,
CFile::shareExclusive | CFile::modeRead | CFile::typeText ) )
{
file.Read(st,50);
file.Close();
}
ASKER
Hi, thanks for your help.
When i used your method, which is:
char* pFileName = "mysetce.txt";
Im getting this error:
'Open' : cannot convert parameter 1 from 'char*' to 'const unsigned short*'
But this below, doesnt give me any error:
CString fname=(_T("mysetce.txt"));
In addition, Im trying to read a file not write to a file.
However, at the point of 'open', i get this 'Assertion failed' message-box which doesnt help me much
When i used your method, which is:
char* pFileName = "mysetce.txt";
Im getting this error:
'Open' : cannot convert parameter 1 from 'char*' to 'const unsigned short*'
But this below, doesnt give me any error:
CString fname=(_T("mysetce.txt"));
In addition, Im trying to read a file not write to a file.
However, at the point of 'open', i get this 'Assertion failed' message-box which doesnt help me much
ASKER
Windows CE does not support CStdioFile
ASKER
But still im having problem even when I use CFile, although not the same problem!
Here is my code:
char pbuf[50];
CFile f;
if( f.Open(L"mysetce.txt",CFil e::modeRea dWrite|
CFile::shareDenyNone) )
{
UINT d= f.Read(pbuf,50);
f.Close();
str = pbuf;
}
The file "mysetce" is a text file and its not empty.
This 'Open' process above goes through with no error and it runs BUT 'pbuf' remains EMPTY !!!!! (it doesn't read into it) WHY?????
Here is my code:
char pbuf[50];
CFile f;
if( f.Open(L"mysetce.txt",CFil
CFile::shareDenyNone) )
{
UINT d= f.Read(pbuf,50);
f.Close();
str = pbuf;
}
The file "mysetce" is a text file and its not empty.
This 'Open' process above goes through with no error and it runs BUT 'pbuf' remains EMPTY !!!!! (it doesn't read into it) WHY?????
What's returned in "d"?
..B ekiM
..B ekiM
How about Rewinding to the beginning, (just a precautionary measure).
Maybe something like
Seek(CFDile::begin, 0 );
I guess it should work then.
Waseem.
Maybe something like
Seek(CFDile::begin, 0 );
I guess it should work then.
Waseem.
ASKER
its retuned zero in "d"
dear waseemanis, my palm top is currently away, so Im going to have to wait for another 2 weeks.
I will let you know as soon as I try your test.
Thanks a lot for your help.
dear waseemanis, my palm top is currently away, so Im going to have to wait for another 2 weeks.
I will let you know as soon as I try your test.
Thanks a lot for your help.
How about trying on Emulator.
ASKER
You cannot test/debug for open/read/write files on the Emulator
So I should wait till I get my palm top back.
Thanks
So I should wait till I get my palm top back.
Thanks
why sure you can...all youy need to do is to empfile to the emulator.
Try it !!
Luck Waseem.
Try it !!
Luck Waseem.
Have you tried something like:
TCHAR szName[32] = TEXT("MyFile.TXT");
and then use szName as your file name in the open call?
Jeff.
TCHAR szName[32] = TEXT("MyFile.TXT");
and then use szName as your file name in the open call?
Jeff.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is there some difference between using CFile and the API MOIN ???
I guess CFile would work perfect.
Luck,
Waseem.
I guess CFile would work perfect.
Luck,
Waseem.
ASKER
Thanks alot for all your help.
But currently Im involved in other projects and my palm-top is away.
I will let you know a.s.a I get it back.
I do appriciate your comments and answers.
Melody
But currently Im involved in other projects and my palm-top is away.
I will let you know a.s.a I get it back.
I do appriciate your comments and answers.
Melody
I think _T macro is giving U a problem
char* pFileName = "mysetce.txt";
CStdioFile f1;
if( !f1.Open( pFileName, CFile::modeCreate
| CFile::modeWrite | CFile::typeText ) ) {
exit( 1 );
}
Hope this help
Regards