The atof function is used to convert a string to a double. Strings in C end with ' 0' and when you do atof(stack[i]) the program does not find ' 0', which would indicate that it is a string, and generates this error, see in the function signature: double atof(const char *str);
Use the Strtok() function to separate your stack variable into several strings according to a separation pattern, the function’s signature is: char *Strtok(char *str, const char *delim), where char *str is the string you want to separate and const char *delim is the string that has the string that will be used to make that separation.
Example of use:
#include <string.h>
#include <stdio.h>
int main(){
char str[80] = "Isto eh - um - teste";
char s[2] = "-";
char *token;
/* pega o primeiro token */
token = strtok(str, s);
/* caminha através de outros tokens */
while( token != NULL ){
printf( " %s\n", token );
token = strtok(NULL, s);
}
return(0);
}
Wow, true! I ended up forgetting that in C to be string has to end with ' 0'. Thank you very much, Matheus!!!
– Lucas Nogueira