I am studying the strtok function code from bsd libc, when I ran it on my machine, the program received a signal SIGSEGVin s[-1] = 0. Here is a link to the code.
Is he s[-1] = 0right?
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include "strtok.c"
int main(int argc, char* argv[]) {
char* str = "xxxx xxxyy fdffd";
const char* s = " ";
char* token = strtok(str, s);
while (token != NULL) {
printf("%s\n", token);
token = strtok(NULL, s);
}
return 0;
}
source
share