You should pay attention to the warnings of th ecompiler
Code:#include <stdio.h>
#include <string.h>
#define ALPHABET_TOTAL 26
int main()
{
/*defining variables*/
FILE *fp;
int text[ALPHABET_TOTAL] = {0},
text_input,
ASCII_count,
alpha;
char filename[20];
/*initializing*/
text_input = 0;
ASCII_count = 0;
alpha = 0;
/*user prompt*/
printf("Type a file name, followed by the <enter> key : ");
if(fgets(filename,sizeof(filename),stdin))
{
char* p = strchr(filename, '\n');
if(p) *p = '\0';
}
else
{
puts("Failed to read a file name");
return 1;
}
fp=fopen(filename,"r");
/*text analysis*/
while( (text_input = fgetc(fp)) != EOF )
{
if(text_input >= 'a' && text_input <= 'z')
text_input -= 'a';
else if(text_input >= 'A' && text_input <= 'Z')
text_input -= 'A';
else
continue;
text[text_input]++;
}
/*display results*/
for (ASCII_count = 0; ASCII_count <= 25; ASCII_count++)
printf("\nTotal %c or %c: %d", ASCII_count + 'a', ASCII_count + 'A',text[ASCII_count]);
return 0;
}