I’m trying to tokenize a string with multiple spaces. For example, "yes___no", where the underscores are spaces. Using strtok(string, " ");
But I am getting a seg fault and after debugging I see after I tokenize the second string is "\024\002" and when printing this incorrect string I get my error.
You cannot change a string literal.
The
strtokabove will try to break thedataat the space by writing a'\0'there:data[3] = '\0';, but string literals are not modifiable. Try insteadEdit: copy a string literal to a character array