char * tok, tok2;
The above statement defines tok
to be of type char *
and tok2
of type char
. It's equivalent to
char *tok;
char tok2;
char *
is not a new type. You should always associate *
with the variable, not the type.
You should change that statement to
char *tok, *tok2;
You cannot assign arrays in C
. Therefore the following statement is wrong -
buffer = "addition 1 2";
What you should do is to initialize the array buffer
with the string literal -
char buffer[] = "addition 1 2";
Also, note that the function strtok
modifies its first argument. Its signature is
char *strtok(char *str, const char *delim);
It's for this reason that the first parameter str
is not const
qualified unlike the second one delim
.