Page 1 of 1

PostPosted: Wed Feb 05, 2003 4:37 pm
by ggravier

I had been using PC on Palm... my app scans a string by accessing various chars in there using variable@[index] syntax.

If I try to compile this on PPC it doesn't work. The initial code is:

string hsn;
int c, value;

hsn=gets("Enter string:");
if (hsn!="")
for ( c=0; c<strlen(hsn) ; c=c+1 )
if ( hsn@[c] > 64 )

How would I write hsn@[c] for the Pocket PC version?


PostPosted: Thu Feb 06, 2003 8:41 am
by guy
To read a character from a string you can use the strgetc() function:

char cChar ;
string sString = "Elephant" ;
int iIndex = 4 ; // Index positions start at 0

cChar = strgetc(sString,iIndex) ; // Set cChar to 'h'

To write a character into an existing string you can use the strsetc() function which returns a new string each time, so is not very efficient.

You can also use the CE API extensions to PocketC:

#include "/pocketc/windef.h"

char cChar ;
string sString = "Giraffe" ;
int iIndex = 4 ;

// Get character; note chars are unicode, so 2 bytes:

cChar = memread16(straddr(sString) + (iIndex * 2)) ; // Returns 'f'

// Write character:

memwrite16(straddr(sString) + (Iindex * 2), 'l') ; // Sets sString to "Giralfe" in place

If you are going to be doing a lot of reading and writing within the string, it's better to convert it into an array of chars:

#include "/pocketc/windef.h"

string sString = "Ferret" ;
char cString[100] ;

memreadArray16(straddr(sString), cString, strlen(sString) + 1) ;

PocketC CE API interface:
PCForm and CE API forum: