storage & retrieval of data to/from files

Discuss topics that apply across the products, such as the PocketC language, or development in general

Postby raveen106 on Sun Apr 04, 2004 2:47 am

For writing a string to file, we have writechars/writebyte in PocketC. To get the string back is there any single command? Similarly for writing and reading int and float numbers to files which commands can be used ? can sombody show me sample code covering the above?


Posts: 3
Joined: Sun Mar 21, 2004 11:25 am

Postby wolfgang on Mon Apr 05, 2004 10:15 pm


integers can be written/read with writeint() and readint(). Please read the PocketC documentation and/or built-in help for those functions.

To write/read a string (terminated with a newline \n), see the code below. To write/read a float, use the same code, PocketC's automatic type conversion will handle conversion between float and string for you.

There are faster, elegant ways to write/read the string, but the code below works reasonably well. Search the PocketC webboard, Guy Sprackland has posted a lot about parsing files.


// write a string to a file, terminate it with a newline
filewrite_nl (int i_fh, string s_string)
return (filewrite (i_fh, s_string + "\n", strlen (s_string) + 1));

// read an single line of text (terminated by a newline)
fileread_nl (int i_fh)
char c;
string s;

while ((c = readbyte (i_fh)) != '\n')
s = s + c;

return (s);

Composing music on the PocketPC! -
Composing music on the PocketPC! -
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest