这样做有什么问题:
void *educator_func(void *param) {
char *lineE = (char *) malloc (1024);
size_t lenE = 1024;
ssize_t readE;
FILE * fpE;
fpE = fopen(file, "r");
if (fpE == NULL) {
printf("ERROR: couldnt open file\n");
exit(0);
}
while ((readE = getline(&lineE, &lenE, fpE)) != -1) {
char *pch2E = (char *) malloc (50);
pch2E = strtok(lineE, " ");
free(pch2E);
}
free(lineE);
fclose(fpE);
return NULL;
}
如果我删除该行'pch2E = strtok(lineE, " ");'
它工作正常...
为什么我不能在strtok()
那里做?我也尝试过,strtok_r()
但没有运气,它给了我无效的免费(地址 0x422af10 在大小为 1,024 的块内是 0 个字节)