Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Reading from a text file?
Page 1 of 1

PostPosted: Thu Oct 10, 2002 9:01 pm
by FurFuznel
I am wondering if anyone knows of any simple ways to read text from a tab delimited text file? or even how to read in only one line of data?

I am currently writing a program on my iPAQ that requires data to be read from a tab delimited text file. I currently have it programmed to grab 1024 characters of text from the file, throw away everything after the last \r, update the file position by the length of the string that was kept, and then parse the string into seperate columns and rows by searching for \t and \r. :?

This would be greatly improved if I could even just read in one line of text at a time. Is there an easier way to do this?

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel

PostPosted: Fri Oct 11, 2002 2:08 am
by Mickle
Many variants of solution...
You use V2 or V3 (with CEAPI)?
Your file is big? (speed of reading is critical parameter?)
Your file is very big? ( > 2-5 MB and you not can allocate memory for full file... )
You needed sequential or random access?

Mickle

PostPosted: Fri Oct 11, 2002 6:49 am
by guy
The method that you are using is probably the best bet for PocketC V2, but you should make sure that the size that you read is the size of the longest line that you are likely to get plus the \r \n on the end. 1024 may be a good starting point but you should cut it back if you can.

The difficulty with PocketC and its standard library is that there is no clean, fast way to search for a character within a string starting at anywhere other than the start. If there was then you could read the whole file in one go, then skip through it one field at a time.

If you use PocketC V3 then you can use some of the functions in the CE API interface to speed things up.

The first thing to do would be to use a real memory buffer for the file reads rather than a PocketC string. You need to use the CreateFile() function to open the file, the LocalAlloc() (or HeapAlloc()) function to allocate a buffer for the file (if possible make it large enough for the whole file), then FileRead() to read as much of the file as possible in one go into the buffer. CloseHandle() closes the file.

You can then use the CEAPI memory helper functions to extract data from the buffer. The memreadUnicodeString() function reads a string from a memory buffer into a PocketC string variable terminating on a delimiter character that you specify (tab would be a good one). It additionally returns the address in the buffer after the delimiter so that you can then use that in the next memeread... to carry on where you left off.

If the file is too big to read in one go then read blocks from it of the largest size that you can. Both LocalAlloc() and HeapAlloc() can allocate buffers of any size up to the maximum available virtual memory (or 1MB on CE 1).

Use LocalFree() (or HeapFree()) to deallocate the buffer at the end of your program. If you decide to use your own heap then you need to create it at the start of your program and destroy it at the end.

A more efficient way to access the file would be to memory map the file. This effectively gives you a memory view of the file in a buffer in memory without having to actually read the file into the buffer. Unfortunately I haven't got round to adding the file mapping functions to CEAPI yet.

There is a link on the CEAPI download page to the Microsoft online documentation for the CE API functions.


Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum

PostPosted: Fri Oct 11, 2002 11:46 am
by FurFuznel
Thanks for the replies! I am currently using PocketC version 3.01 and might even have the CE API from sometime ago. I shall go download your latest version and give your method a try. The files that I am reading in are never more than about 50 kB so I should be able to read the whole file in easily.

Thanks for the suggestions, keep up the good work.

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel

PostPosted: Wed Oct 16, 2002 10:50 am
by FurFuznel
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by guy</i>
The first thing to do would be to use a real memory buffer for the file reads rather than a PocketC string. You need to use the CreateFile() function to open the file, the LocalAlloc() (or HeapAlloc()) function to allocate a buffer for the file (if possible make it large enough for the whole file), then FileRead() to read as much of the file as possible in one go into the buffer. CloseHandle() closes the file.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">
Sounds good to me, but when I attempted to do this the compiler told me it did not know CreateFile(), so I included windef.h (I was already including windefs.h) but all that did was cause the program to not know what NULL was during compile time. What do I need to $include to get the CreateFile() command to work.

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
You can then use the CEAPI memory helper functions to extract data from the buffer. The memreadUnicodeString() function reads a string from a memory buffer into a PocketC string variable terminating on a delimiter character that you specify (tab would be a good one). It additionally returns the address in the buffer after the delimiter so that you can then use that in the next memeread... to carry on where you left off.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

I guess I had better ask what I need to include to make these commands work as well.

Thank you for any and all assistance that you can provide at this time.

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel

PostPosted: Wed Oct 16, 2002 12:20 pm
by guy
CreateFile() is defined in winbase.h

To check which header file you need for each function look at the table at the very end of the page of the Microsoft documentation for the function, under "Requirements".

For example, the CreateFile() documentation at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/htm/_wcesdk_Win32_CreateFile.asp

States that winbase.h is needed in the "Defined in" column of the table.

There is a link to the Microsoft documentation on the CEAPI download page.

Instead of using windefs.h and pcheader.h as you would in a standard PocketC application, use winuser.h which includes all of windefs and pcheader.

Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum

PostPosted: Wed Oct 16, 2002 1:35 pm
by FurFuznel
Thank you once again for your assistance. The funny/sad part of all of this is that I was at that page on the Microsoft site looking at how to read the command and did not notice that they provided the answer right there.

Thank you for the help I will make those changes, give it all a try, and be back with my next silly question. ;)

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel

PostPosted: Thu Oct 17, 2002 1:33 pm
by ianf
In Space Treker ( PocketC V2 compiler game ) I used fixed length and variable length text file routines. I still have the source if you want me to e-mail it to you. The variable length source came from someone else's sample which I got via this site's resources so the original may still be around

PostPosted: Thu Oct 17, 2002 1:44 pm
by FurFuznel
Thanks, that would be great. You can e-mail it to me at tjl128 @mail.usask.ca (without the space). I have not managed to get the CreateFile() method to work yet, so I would be interested in what has been done before.

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel

PostPosted: Tue Oct 22, 2002 1:59 pm
by ianf
Sorry, I only come around every week or so. I will e-mail the source once I get a minute.

PostPosted: Sun Oct 27, 2002 5:14 am
by ianf
I have e-mailed the file functions today from my AOL account


Regards

Ian

PostPosted: Mon Oct 28, 2002 5:43 pm
by FurFuznel
Thanks Ianf;

I have received the information but have not had time to check it out yet. From my first glance at it, many of your functions seem similar to the way that I was doing things.

I will let you know if I have any troubels with it!

Thanks once again!

FurFuznel

===========================
"Mental Anguish is for those who choose to think!" - FurFuznel