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

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

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112
[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:112)
[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:112)
[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:112)
[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:112)
OrbWorks Community Forum • View topic - Reading CSV Files on PocketC for Palm

Reading CSV Files on PocketC for Palm

Discuss PocketC for Palm OS (including Desktop Edition)

Postby larrymart on Sat Dec 23, 2006 3:49 pm

A long time ago I used PocketC for windows CE and am now trying PocketC for Palm. I would like to convert the listed code from CE to Palm and am having trouble. I would appreciate if the listed code would be reviewed and any help I could get.
Regards
Larry
larrymart
 
Posts: 2
Joined: Sat Dec 23, 2006 3:35 pm
Location: USA

Postby larrymart on Sat Dec 23, 2006 3:54 pm

// Sorry that I left the code out



main() {
string sFile ; // Name of file to read
string sContents ; // The whole content of the file
string sLine ; // The current line from the file
string sField ; // The current field on the line
int iFile ; // The file handle to acces the CSV file
int iEof = 0 ; // End of file flag
int iPos ; // Position of search chracter in contents/line
int iLine = 0 ; // Row number in file
int iField ; // Field/column number on row
// Get the name of the file to open
sFile = OpenFileDlg("CSV files (*.csv)|*.csv") ;
if (sFile != "") {
// Open the file
iFile = fileopen(sFile, 0, FILE_READ) ;
if (iFile != -1) {
// Read the whole file and then close it

sContents = fileread(iFile, 32767) ;
fileclose(iFile) ;

// Now step through each line, extract the fields from the
// line and display them

showconsole() ;

do {

// Find next end of line marker

iPos = strchr(sContents, 13) ;

// If there is one then remove line from contents, else use
// everything that's left and set the end of file flag

if (iPos != -1) {
sLine = strleft(sContents, iPos) ;
sContents = strmid(sContents, iPos + 2, 32767) ;
} else {
sLine = sContents ;
iEof = 1 ;
}

// If the line isn't blank and we haven't run off the end
// of the file

if (strlen(sLine)) {

// Count the row number and display it

puts("Row " + iLine++ + ": ") ;
iField = 0 ;

// Now chop out all of the fields from the line
// For now assume that we can't have commas in quoted fields

do {
iPos = strchr(sLine, ',') ;

// If we found a comma then get everything up to that
// point, if we didn't then field is everything left
// on the line

if (iPos != -1) {
sField = strleft(sLine, iPos) ;
sLine = strmid(sLine, iPos + 1, 32767) ;
} else {
sField = sLine ;
}

// Display the field

puts("Field " + iField++ + ": " + sField + "\t") ;

// Repeat for each field on the line

} while (iPos >= 0) ;
putsl("") ;
}

// Repeat for each line in the file

} while (iEof == 0) ;

} else {
alert("Cannot open file " + sFile) ;
}
}
}
larrymart
 
Posts: 2
Joined: Sat Dec 23, 2006 3:35 pm
Location: USA

Postby dewey on Wed Dec 27, 2006 4:41 pm

What specifically are you having trouble with?
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests

cron