March 28, 2024, 02:16:46 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Text file question

Started by Haim, November 19, 2007, 05:29:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

Hello,
I have a text file with strings that may be longer than 255 characters.
How can I read the file?
Readstring with maxbytes >255 crashes!

Help please

Haim

Barney

This is taken from the help file:

STRING - A string of characters up to a length of 255
DSTRING - A dimensionable string that can contain any number of characters.
WSTRING - A unicode string up to a lnegth of 255 characters.
DWSTRING - A dimensionable unicode string that can contain any number of characters.

Barney

Haim

Barney,
I tried Dstring dimensioned to more than 255, but it crashed

Haim

Bruce Peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

John S

Haim,
Below is some code I have used to read a text file into my program:


TabDlg::LoadHelpText()
{
dstring helptext[6595];
unsigned int hFile = OpenFile(GetStartPath()+"HelpText.txt", MODE_READ);
if(hFile)
{
Read( hFile, helptext, len(byte)*6595 );
m_help_txt->SetText( helptext );
}
return true;
}
John Siino, Advanced Engineering Services and Software

Haim

November 19, 2007, 11:14:43 AM #5 Last Edit: November 19, 2007, 11:23:16 AM by Haim
Hello,
Thank you all for your responses.
I was trying to read a text file with lines of varying length, so I had to use somethig like readstring() and not read() which requires a size parameter.

I am still puzzling over it... :-[

Just fixed it but I do not understand why.

This crashed the program:

uint hfile=openfile("C:\program files\aurora\examples\ur\ITD UR OCTOBER 2007.csv",mode_read);
dstring s[300];
if hfile
{
   readstring(hfile,s,280);
   print(s);
closefile(hfile);
}

I fixed it by chnging
dstring s[300] to dstring s[500];

Why does this work???