Ok, I think I'm using fgets properly...
This program is doing my head in. I'm struggling. It doesn't work. Any freindly help would be greatly appreciated!
Code:
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, Ctrl+Z, and then <enter key> again : ");
fgets(filename,100, stdin);
fp=fopen(&filename[0],"r");
/*text analysis*/
while( text_input != EOF )
{
alpha = 1;
text_input = getchar();
if(text_input >= 'a' && text_input <= 'z')
text_input -= 'a';
else if(text_input >= 'A' && text_input <= 'Z')
text_input -= 'A';
else
alpha = 0;
if(alpha)
text[text_input]++;
}
/*display results*/
for (ASCII_count; ASCII_count <= 25; ASCII_count++)
printf("\nTotal %c or %c: %d", ASCII_count + 'a', ASCII_count + 'A',text[ASCII_count]);
}