For my C class I have to write a program that counts the frequency of each digit(0-9) that is in a file. I wrote the code in Java already but cant translate it into C. Any help would be appreciated. I will add what I have so far below. A portion of the text file was added to the end of the code to show what it looks like, a random string of symbols and numbers.
#include<stdio.h>
#define m 100
#define n 60
void main() {
char file_name[m]; FILE *input_file;
char symb, symb0, symb1, symb2, symb3, symb4, symb5, symb6;
char symb7, symb8, symb9;
int i;
printf("Enter name of the input file: "); scanf("%s", file_name);
input_file = fopen(file_name, "r");
while (input_file == NULL) {
printf("Error: There is no file \"%s\"\n", file_name);
printf("Enter file name (or \".\" to exit): "); scanf("%s", file_name);
if (strcmp(file_name, ".") == 0) return;
input_file = fopen(file_name, "r");}
//read each char of the file till the end
while ((symb=getc(input_file))!=EOF){
// if the char is between '0'-'9' print it
if(symb >= '0' && symb <='9'){
//printf("%c", symb);
switch(symb){
case '0' :
symb0++;
break;
case '1' :
symb1++;
break;
case '2' :
symb2++;
break;
case '3' :
symb3++;
break;
case '4' :
symb4++;
break;
case '5' :
symb5++;
break;
case '6' :
symb6++;
break;
case '7' :
symb7++;
break;
case '8' :
symb8++;
break;
case '9' :
symb9++;
break;
}
printf("%c", symb3);
}
}
printf("\n-= Count the Thisles in =-");
fclose(input_file);
}
//...1..1.'`.1.........2..2..2...../\......./%%%%\/%%\.3...4..
//......'............../\........./%%\../\./%%%%%%/\%%\33..4..
//...'.../\.........../%%\.../\.../%%\./%%\%/\%/\/%%\%/\......
//.'..../%%\./\......./%%\../%%\./%%%%\/%%\/%%\%%\%%%/%%\.55..