程序分離文件並逐個打印文字,但是當我編譯並運行它時,它表示分段錯誤。字計數器中的分段錯誤
的main
部分:
char * w;
int Counter = 0;
while ((w = nextword(fd)) != NULL) {
printf("%d: %s\n", Counter, w);
Counter++;
}
printf("words total = %d\n", Counter);
功能nextword
:
char * nextword(FILE * fd) {
int c;
int i;
c = fgetc(fd);
while (c != -1) {
while ((c != ' ') && (c != '\n')) {
word[wordLength] = c;
wordLength++;
}
return word;
wordLength = 0;
}
凡'wordLength'聲明?它的價值是什麼? – Axalo 2015-02-05 17:16:09