#include <stdio.h>
int main (void) {
FILE *fp;
fp = fopen("test.txt", "r");
int char_counter, i, c;
int word_length[12];
char_counter = 0;
for (i = 0; i <= 12; i++) {
word_length[i] = 0;
}
while ((c = getc(fp)) != EOF) {
if (c == '\n' || c == '\t' || c == ' ')
{
word_length[char_counter] = word_length[char_counter] + 1;
char_counter = 0;
}
else {
++char_counter;
}
}
for (i = 0; i <= 12; i++) {
printf("%d %d\n", i, word_length[i]);
}
return 0;
}
있는 test.txt :히스토그램
blahblahblah blahblah 어쩌구 저쩌구 BL BB
출력 :
0 0
1 1
2 1
3 1
4 1
5 0
6 0
7 0
8 1
9 0
10 0
11 0
12 -1 <-- ??
예상 출력이 같은 보이지만이 -1이 아닌 12 행에서 1이어야합니다. 나는 어떻게 내가 음수를 얻었는지 정말로 이해하지 못한다. 이 snippt에서
KandR 운동 1-13/1-14를하고 있습니까? – Sam
하하하, 네! – lche
나는 운동 1-13을 게시했다. 원하는 경우 운동 1-14를 게시하십시오 – Sam