You are required to open an input file shown below then read
You are required to open an input file (shown below) then read one character at a time until it is finished. While reading the content of the file, keep a count of the following:
1) Count of each digit read. The counts should be kept in an int array of size 10.
2) Count of each alphabetic character read irrespective if it is an upper case or lower case. The counts should be kept in an int array of size 26.
3) Count of other characters (Not a digit and not an alphabet). Whitespace character such as newline \ , blank or tab \\t should NOT be counted here. Hence, if you find ! ; @ the count will be 3; you will ignore spaces. This will just be an int value.
4) Total count. This will be the count for everything read, including blanks, new line, etc. Again, this will be an int value.
After reading and processing the file, and get each count correctly, you will need to sort the count values in numerical order (lowest to highest) before displaying the result.
Your solution must use FUNCTIONAL DECOMPOSITION.
Hence, if the input file was the one given below, your unsorted output is shown below. Please note that your output must also has the values sorted in numerical order from lowest to highest.
Here is the content of your input file.
Here will be the output generated, minus the gap. That\'s just the end of the page.
Solution
int main(int argc, char *argv[]) {
#include<stdio.h>
FILE *ptr_file;
char buf[1000];
int digit[10];
int alpha[26];
int other=0;
char alp=65;
int i;
for(i=0;i<=9;i++)
digit[i]=0;
for(i=0;i<=25;i++)
alpha[i]=0;
ptr_file =fopen(\"D:/input.txt\",\"r\");
if (!ptr_file)
return 1;
while (fgets(buf,1000, ptr_file)!=NULL)
printf(\"\ Original File:=>\ \");
printf(\"%s\ \",buf);
fclose(ptr_file);
for(i=0;buf[i]!=NULL;i++)
{
//Digits Count
if(buf[i]==\'0\')
digit[0]=digit[0]+1;
if(buf[i]==\'1\')
digit[1]=digit[1]+1;
if(buf[i]==\'2\')
digit[2]=digit[2]+1;
if(buf[i]==\'3\')
digit[3]=digit[3]+1;
if(buf[i]==\'4\')
digit[4]=digit[4]+1;
if(buf[i]==\'5\')
digit[5]=digit[0]+1;
if(buf[i]==\'6\')
digit[6]=digit[6]+1;
if(buf[i]==\'7\')
digit[7]=digit[7]+1;
if(buf[i]==\'8\')
digit[8]=digit[8]+1;
if(buf[i]==\'9\')
digit[9]=digit[9]+1;
//Alphabatic count
if(buf[i]==\'a\'||buf[i]==\'A\')
alpha[0]=alpha[0]+1;
if(buf[i]==\'b\'||buf[i]==\'B\')
alpha[1]=alpha[1]+1;
if(buf[i]==\'c\'||buf[i]==\'C\')
alpha[2]=alpha[2]+1;
if(buf[i]==\'d\'||buf[i]==\'D\')
alpha[3]=alpha[3]+1;
if(buf[i]==\'e\'||buf[i]==\'E\')
alpha[4]=alpha[4]+1;
if(buf[i]==\'f\'||buf[i]==\'F\')
alpha[5]=alpha[5]+1;
if(buf[i]==\'g\'||buf[i]==\'G\')
alpha[6]=alpha[6]+1;
if(buf[i]==\'h\'||buf[i]==\'H\')
alpha[7]=alpha[7]+1;
if(buf[i]==\'i\'||buf[i]==\'I\')
alpha[8]=alpha[8]+1;
if(buf[i]==\'j\'||buf[i]==\'J\')
alpha[9]=alpha[9]+1;
if(buf[i]==\'k\'||buf[i]==\'K\')
alpha[10]=alpha[10]+1;
if(buf[i]==\'l\'||buf[i]==\'L\')
alpha[11]=alpha[11]+1;
if(buf[i]==\'m\'||buf[i]==\'M\')
alpha[12]=alpha[12]+1;
if(buf[i]==\'n\'||buf[i]==\'N\')
alpha[13]=alpha[13]+1;
if(buf[i]==\'o\'||buf[i]==\'O\')
alpha[14]=alpha[14]+1;
if(buf[i]==\'p\'||buf[i]==\'P\')
alpha[15]=alpha[15]+1;
if(buf[i]==\'q\'||buf[i]==\'Q\')
alpha[16]=alpha[16]+1;
if(buf[i]==\'r\'||buf[i]==\'R\')
alpha[17]=alpha[17]+1;
if(buf[i]==\'s\'||buf[i]==\'S\')
alpha[18]=alpha[18]+1;
if(buf[i]==\'t\'||buf[i]==\'T\')
alpha[19]=alpha[19]+1;
if(buf[i]==\'u\'||buf[i]==\'U\')
alpha[20]=alpha[20]+1;
if(buf[i]==\'v\'||buf[i]==\'V\')
alpha[21]=alpha[21]+1;
if(buf[i]==\'w\'||buf[i]==\'W\')
alpha[22]=alpha[22]+1;
if(buf[i]==\'x\'||buf[i]==\'X\')
alpha[23]=alpha[23]+1;
if(buf[i]==\'y\'||buf[i]==\'Y\')
alpha[24]=alpha[24]+1;
if(buf[i]==\'z\'||buf[i]==\'Z\')
alpha[25]=alpha[25]+1;
if(buf[i]!=\'0\'&buf[i]!=\'1\'&buf[i]!=\'2\'&buf[i]!=\'3\'&buf[i]!=\'4\'&buf[i]!=\'5\'&buf[i]!=\'6\'&buf[i]!=\'7\'&buf[i]!=\'8\'&buf[i]!=\'9\'&buf[i]!=\' \'& buf[i]!=\'a\'& buf[i]!=\'A\'& buf[i]!=\'b\'& buf[i]!=\'B\'& buf[i]!=\'c\'& buf[i]!=\'C\'& buf[i]!=\'d\'& buf[i]!=\'D\'& buf[i]!=\'e\'& buf[i]!=\'E\'& buf[i]!=\'f\'& buf[i]!=\'F\'& buf[i]!=\'g\'& buf[i]!=\'G\'& buf[i]!=\'h\'& buf[i]!=\'H\'& buf[i]!=\'i\'& buf[i]!=\'I\'& buf[i]!=\'j\'& buf[i]!=\'j\'& buf[i]!=\'k\'& buf[i]!=\'K\'& buf[i]!=\'l\'& buf[i]!=\'L\'& buf[i]!=\'m\'& buf[i]!=\'M\'& buf[i]!=\'n\'& buf[i]!=\'N\'& buf[i]!=\'o\'& buf[i]!=\'O\'& buf[i]!=\'p\'& buf[i]!=\'P\'& buf[i]!=\'q\'& buf[i]!=\'Q\'& buf[i]!=\'r\'& buf[i]!=\'R\'& buf[i]!=\'s\'& buf[i]!=\'S\'& buf[i]!=\'t\'& buf[i]!=\'T\'& buf[i]!=\'u\'& buf[i]!=\'U\'& buf[i]!=\'v\'& buf[i]!=\'V\'& buf[i]!=\'w\'& buf[i]!=\'W\'& buf[i]!=\'x\'& buf[i]!=\'X\'& buf[i]!=\'y\'& buf[i]!=\'Y\'& buf[i]!=\'z\'& buf[i]!=\'Z\')
other++;
}
printf(\"\ Digit Count: \ \");
for(i=0;i<=9;i++)
printf(\"%d : %d , \\t\",i,digit[i]);
printf(\" Alhabets Count:\ \");
for(i=0;i<=25;i++)
printf(\"%c : %d, \\t\", alp++,alpha[i]);
printf(\"\ Other Count:\ \");
printf(\"%d \",other);
return 0;
}



