Hi all,
I am writting a program which should from file read numbers (in this case 1-digit and 2 -digit) and then count how many times which number fall...in file from which program should read numbers are written like this... 1 2 3 4 5 6 7 8 9 10 11 12
and result after compiling and running is 1 2 3 4 5 6 7 8 9 10 11 12(it writes them all good)
but when he is counting...there are mistakes...
num 1:2
num 2:1
num 3:1
num 4:1
num 5:1
num 6:1
num 7:1
num 8:1
num 9:0 (all others are 0)

problem is that he si not counting them all...and he is not counting 2-digit numbers right...for example if we put first 9 numbers...he will count good first 8...9.number does not exist for him...and the second problem is that for example 12 he is not counting like 2-digit number...but as two 1-digit numbers 1 and 2....i dont know how to solve this...thanks for help....

Code:
#include <stdio.h>
#include <stdlib.h>

int main() {
FILE *inputfile;
int c,d;
int b[21]={0};

inputfile=fopen("input1.txt","r");

if(inputfile == NULL) {
printf("I cant open file \n");
exit(1);
}


while((c=getc(inputfile))!=EOF ) {
printf("%c",c);
for(d=1;d<21;d++){
if(c==d+49) b[d]++;
}
}

printf("\n\n 1: %d  \n 2: %d  \n 3: %d  \n 4: %d  \n 5: %d  \n",b[1],b[2],b[3],b[4],b[5]);
printf(" 6: %d  \n 7: %d  \n 8: %d  \n 9: %d  \n10: %d  \n",b[6],b[7],b[8],b[9],b[10]);
printf("11: %d  \n12: %d  \n13: %d  \n14: %d  \n15: %d  \n",b[11],b[12],b[13],b[14],b[15]);
printf("16: %d  \n17: %d  \n18: %d  \n19: %d  \n20: %d  \n",b[16],b[17],b[18],b[19],b[20]);

fclose(inputfile);

getch();
return 0;
}