im trying to tokenize some strings so that the numbers are tokens themselves so i can eventually add them but my tokenization is not working and im not sure why. It compiles correctly but when i execute the file it says "segmentation fault", anyone know why or how to get the number as tokens?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stringSum(char *s);
/*void minMaxValues(char *s, int *min, int *max);*/
int main(void)
{
int value,i;
char* text[] = { "1 + 2 + 3 + 4",
"7",
"30 + 20 + 10",
"9 + 900 + 90000 + 9000 + 90" };
for(i=0;i<4;i++) /*send strings to function*/
stringSum(text[i]);
}
int stringSum(char *s)
{
char* del = " + ";
char* token;
token = strtok(s,del);
while(token != NULL)
{
printf("%s\n",token);
token = strtok(NULL, del);
}
}