I'm working on an assignment that I can't figure out. The instructions were to create a program that reads in an input file of integers, and prints out the number of times any number from 0-9 appears. I can only use THREE variables (an array counts as one). The problem I have is that the program is supposed to detect the EOF and stop scanning there. My program isn't doing this.

A sample run would be if the input file had: 1 2 4 3 5 8 9 9 9 9 5 3 2 38 39 92 0 3

The output would be:

1 0's

1 1's

2 2's

3 3's

1 4's

2 5's

0 6's

0 7's

1 8's

4 9's

It ignores any number that is not between 0 and 9. Here is my program so far. Everything seems to work except I am getting a segmentation fault when running it... PLEASE HELP! THANK YOU!

Code:

int main() {
int vals[10];
int numCount[10];
int i;
while (scanf("%d", &vals[i]) !=EOF) {
vals[i] = 0;
i++;
}
while (scanf("%d", &vals[i]) !=EOF) {
i++;
if (vals[i] == 0) {
numCount[0] = numCount[0] + 1;
}
if (vals[i] == 1) {
numCount[1] = numCount[1] + 1;
}
if (vals[i] == 2) {
numCount[2] = numCount[2] + 1;
}
if (vals[i] == 3) {
numCount[3] = numCount[3] + 1;
}
if (vals[i] == 4) {
numCount[4] = numCount[4] + 1;
}
if (vals[i] == 5) {
numCount[5] = numCount[5] + 1;
}
if (vals[i] == 6) {
numCount[6] = numCount[6] + 1;
}
if (vals[i] == 7) {
numCount[7] = numCount[7] + 1;
}
if (vals[i] == 8) {
numCount[8] = numCount[8] + 1;
}
if (vals[i] == 9) {
numCount[9] = numCount[9] + 1;
}
}
for (i = 0; i < 10; i++) {
printf("%d %d's\n", numCount[i], i);
}
}