I have the following code
int eval(char* string) {
char* token;
outputString[0] = NULL;
token = strtok(string, " ");
while(token != NULL){
if(strstr((char *) token, "@") != NULL) {
strcat(outputString, "@");
token = calc(token);
}
strcat(outputString, token);
strcat(outputString, " ");
token = strtok(NULL, " ");
}
printf("%s\n", outputString);
}
It is called on a string that looks like this
The water has @TREE and @SKY in it.
This code works completely fine. However I want to make it more efficient.
The code is supposed to do the following --
Cut the string up by spaces, however, if an @
is found, it should be sent away to be evaluated by calc();
. If none are found, we continue splitting the string by spaces until one is actually found. While we are running through, we concatenate it onto outputString and continue forward.
aaa@bbb
and similar tokens should be processed? \$\endgroup\$