Link to home
Start Free TrialLog in
Avatar of coldest
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();

}


Avatar of inpras
inpras

Hi use this
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
Avatar of coldest

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
Avatar of coldest

ASKER

Windows CE does not support CStdioFile
Avatar of coldest

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",CFile::modeReadWrite|
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
How about Rewinding to the beginning, (just a precautionary measure).
Maybe something like
Seek(CFDile::begin, 0 );

I guess it should work then.

Waseem.
Avatar of coldest

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.
How about trying on Emulator.
Avatar of coldest

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
why sure you can...all youy need to do is to empfile to the emulator.
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.
ASKER CERTIFIED SOLUTION
Avatar of Moin
Moin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there some difference between using CFile and the API MOIN ???
I guess CFile would work perfect.

Luck,
Waseem.
Avatar of coldest

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