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();

}


coldestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
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
0
coldestAuthor Commented:
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
0
coldestAuthor Commented:
Windows CE does not support CStdioFile
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

coldestAuthor Commented:
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?????
0
mikeblasCommented:
What's returned in "d"?

..B ekiM
0
waseemanisCommented:
How about Rewinding to the beginning, (just a precautionary measure).
Maybe something like
Seek(CFDile::begin, 0 );

I guess it should work then.

Waseem.
0
coldestAuthor Commented:
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.
0
waseemanisCommented:
How about trying on Emulator.
0
coldestAuthor Commented:
You cannot test/debug for open/read/write files on the Emulator

So I should wait till I get my palm top back.

Thanks
0
waseemanisCommented:
why sure you can...all youy need to do is to empfile to the emulator.
Try it !!
Luck Waseem.
0
jgalt00Commented:
Have you tried something like:
TCHAR szName[32] = TEXT("MyFile.TXT");
and then use szName as your file name in the open call?

Jeff.
0
MoinCommented:
If you are not stuck with CFile you can use the following code fragment:


HANDLE hFile;
hFile = CreateFile(_T("MyFile.txt"), GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);  

if (hFile == INVALID_HANDLE_VALUE)
{
   AfxMessageBox((LPCTSTR)"Unable to open file", MB_OK, 0);
}
//else
//      AfxMessageBox((LPCTSTR)"File opened", MB_OK, 0);

And then use this statement to read data:
char ch;
DWORD dwBytesRead;
ReadFile(hFile, &ch, 1, &nBytesRead, NULL) ;

Hope it will work fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waseemanisCommented:
Is there some difference between using CFile and the API MOIN ???
I guess CFile would work perfect.

Luck,
Waseem.
0
coldestAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.