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 - fileread() question

fileread() question

Discuss PocketC for CE (including Desktop Edition)

Postby edward on Tue Feb 06, 2001 6:06 am

Hello,

I'm a beginner of PocketC. And here is my question. I have a file the format is as this, one line of English and one line of Chinese, just like this:

English
Chinese
English
Chinese
...

I want to write a program to get English words as a string and then Chinese words as another string. Because PocketC doesn't have a equivalent for gets(), we have to use fileread() to get file data. At the beginning, I tried to get a fix lenghth of data and separate English and Chinese by finding carriage return in the string and then fileseek to proper position and read next, just like following:

data=fileread(fh, MAXL);
//read fix length of data
index= strchr(data, '\r');
//find carriage-return in data
eng=strleft(data,index);
//get English words in first line
fpos=fpos+index+2;
//caculate file position fpos
fileseek(fh, fpos,0);
//put file pointer accordingly and read next

If all the text is English, this code will work. But with Chinese in the text, this becomes quite complicated. strchr() treats Chinese character, which is actually two-bytes, as one character, that's good. But fileseek doesn't work that way. This causes the next read failed. And because the second line in text file is mixed of Chinese and English, that makes the whole thing even worse.

Can someone give me a solution of this or a alternative way which has the same result as gets()?

Thanks and regards,

Edward
edward
 
Posts: 10
Joined: Tue Feb 06, 2001 5:30 am

Postby ianf on Tue Feb 06, 2001 7:24 am

Hi Edward,
If reading variable length records is what you need then this is simple enough. I used a source file from the CE resources page on this site with a few changes to do my own file handling. If you can't find this now (I got it a long time ago ) let me know & I will e-mail some code.

ps: PocketC supports unicode in file handling as well as ascii. Does this help?

Ian
ianf
 
Posts: 92
Joined: Mon Dec 11, 2000 7:25 am
Location: United Kingdom

Postby edward on Tue Feb 06, 2001 8:01 am

Hi! Ian,

Thank you so much for your help. I think perhaps what you said can help solve my problem. I tried to find the example code you mentioned but failed. Could you please send me the code for reading variable length records? My mail address is

e_whitejr@yahoo.com

Thanks in advance.

Edward.
edward
 
Posts: 10
Joined: Tue Feb 06, 2001 5:30 am

Postby edward on Wed Feb 07, 2001 3:58 am

Hi, Ian,

Thank you so much for the help. This code is similar with what I posted in the forum. It will work perfect with ASCII file. But with mixed Chinese and English text file, it will fail. Because PocketC counts one Chinese character, which is actually two-bytes character, in string function as one. But counts one Chinese character in fileseek or fileread as two. So I think that converting my original file to Unicode may be helpful to my problem.

Thanks and regards,

Edward
edward
 
Posts: 10
Joined: Tue Feb 06, 2001 5:30 am


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 2 guests

cron