Hi all I'm studying C and I have to do an exercise that requires me to open a file and count the number of times a letter occurs,either small or capital.
For example,I have a text file in C:\text.txt with the contents "World In Conflict".So in my example the letter "c" is counted twice.After I have finished counting the letters,I have to make
a graphical representation that's to be like this :
6 |
5 |
4 |
3 |
2 | *
1 | * *
- + - - - - - -
| A B C D E F
that's from A to F,obviously I need from A-Z.
This is what I have done so far :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
FILE *a;
char b;
int count;
int main()
{
clrscr();
a=fopen("C:\\text.txt","r");
while (1)
{
b=fgetc(a);
if (b>64 && b<91) ++count
if (b>97 && b<122) ++count
if (b==EOF)
break;
}
fclose(a);
printf("letters %d",count);
getch();
}
I thought using ASCII would be a good idea,but how can I specifically count the letters using ASCII ? I could do it using
if (b == "a" && b == "A") ++counta (this counts all "a"s and "A"s)
for all letters,but I don't think that's the point of this exercise.
Also,how do I design the GUI ? Our teacher said we should use "gotoxy" but I haven't been able to get a handle on it.
Any help would be much appreciated.