Page 1 of 1

PostPosted: Tue Feb 06, 2001 6:06 am
by edward

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:


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
//get English words in first line
//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,


PostPosted: Tue Feb 06, 2001 7:24 am
by ianf
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?


PostPosted: Tue Feb 06, 2001 8:01 am
by edward
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

Thanks in advance.


PostPosted: Wed Feb 07, 2001 3:58 am
by edward
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,