txt ファイルを読み取ろうとしていますが、必要な行を取得できますが、この行のすべての単語を 1 つずつ出力することはできません。
例: 行は次のようになります。
hello world 1 2 3
そして、次のように1つずつ印刷する必要があります。
hello
world
1
2
3
セグメンテーション違反のコア ダンプ エラーが発生しました
char temp[256];
while(fgets(temp, 256, fp) != NULL) {
...
int tempLength = strlen(temp);
char *tempCopy = (char*) calloc(tempLength + 1, sizeof(char));
strncpy(temCopy, temp, tempLength); // segmentation fault core dumped here;
// works fine with temp as "name country"
name = strtok_r(tempCopy, delimiter, &context);
country = strtok_r(Null, delimiter, &context);
printf("%s\n", name);
printf("%s\n", country);
}
コードの修正を手伝ってくれる人はいますか?
ありがとう!