I currently am trying to extract a substring within a bufferline. The goal is to parse the string by whitespace and symbols to compile later. The line I'm trying to parse is the first line of my file.
void append(char* s, char c)
{
int len = strlen(s);
s[len] = c;
s[len+1] = '\0';
}
int main(void){
char str[] = "program example(input, output);";
char *f = str;
char *b = str;
char token[10];
if(*f != '\0'){
while (*f != ' ')
{
append(token,*f);
f++;
}
f++;
printf("%s",token);
token[9] = '\0';
}
return 0;
}
Am I clearing the token string wrong? The code only returns:
program
but it should return
program
example(input,
output);