ern wrote on 20/09/05 :
I'm using scanf("%s",userInput) to capture up to three words from the
user. I want to seperate those three words into three variables:
char * firstWord;
char * secondWord;
char * thirdWord;
These variables are just uninitialized pointers. If you insist in using
scanf(), you probably want a static or dynamic array of char.
Is there an easy way/function that can do this already? Thanks!
fgets() and a hand made parser using strchr(), strstr() etc.
Of course, there is a strtok() function that can be used to separate
tokens, but it has many caveats.
I think that POSIX.1 defines strtok_r() and strsep() that are better.
But they are not standard and probably not portable everywhere.
http://www.hmug.org/man/3/strtok_r.php
--
Emmanuel
The C-FAQ:
http://www.eskimo.com/~scs/C-faq/faq.html
The C-library:
http://www.dinkumware.com/refxc.html
"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC