|
From: Per W. <pw...@ia...> - 2003-03-05 13:24:55
|
Be very, VERY careful of strtok(), since it requires the change of your
original buffer. It inserts '\0' characters at the end of the token, but
that might be a valid character of something new, i.e.
char *p,buf[] = "charlie(a,b);"
p = strtok(buf,"(),\n\r");
if (p && !strcmp(p,"charlie")) {
// oops, did strtok end with a '(', ')', '\n', '\r' or '\0' or what?
// information has been overwritten :-(
}
/Per W
On Tue, 4 Mar 2003, Matthews wrote:
> A small question:
>
> I'm in the process of creating a scripting language for a game creation
> system that I use. The method I use is to
>
> 1) Grab a line (seperated by semi-colons like C) from the file
> 2) Get the length of the command (with a small for() loop that increments a
> length variable until a space is reached)
> 3) Compare the string to each valid command
> 4) If a match is found, perform a parameter count (a variation of the
> previous loop) and make sure there are the correct number
> 5) Write command bytecode with parameters to compiled script file.
>
> This almost works perfectly, there's a strange bug related to a two-part
> command that sometimes makes the compiler believe there's one more
> parameter than there actually is. That's not my question though. My
> question is how could strtok() help me in this situation I've described?
> I'm not sure how it works, and I'm wondering if it could make my job easier
> by breaking the line down into different parts for easy counting/comparing.
>
> Thanks in advance.
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|