--- bill <[EMAIL PROTECTED]> wrote:
> Thanx for your responses,
Maybe the following two functions will serve as an example of how you
can pass a string to a function and how the function can return a
string.
/******************************************************************
FirstWord - returns (in 'word') the first word in 'sentence'.
A word is some chars ending in a space. If there are no spaces,
just return a copy of the whole sentence.
******************************************************************/
static void FirstWord( Char * word , Char * sentence )
{
Char * p;
// locate a space
p = StrChr(sentence, ' ');
if (p)
// found a space, so copy the word
StrNCopy(word, sentence, (p - sentence));
else
// didn't find a space
StrCopy(word, sentence);
}
static void testFirstWord( void )
{
Char aSentence[] = "What's up, doc?"; // an array of Chars
Char * aWord; // a pointer to Char
// get some memory. may need enuf to hold a whole sentence
aWord = MemPtrNew( 16 );
// call the function
FirstWord( aWord, aSentence );
// look at the result
WinDrawChars( aWord, StrLen(aWord), 10, 20 );
// free up the memory
MemPtrFree( aWord );
}
That's the end of today's lesson on the C programming language. Since
this is not a forum for C language questions, I've probably already
said more than I should have.
In the future, please try to ask actual Palm OS programming questions.
For example, if you need help understanding how StrNCopy() is different
from strncpy, even after reading the docs.
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/