hello everyone i need help with an assignemnt that askes me to read from a file and count the number of occurence of each letter in the alphabet . im stuck trying to group each letter in an array. i think using a switch statement would be the easiest way but dont know how to make it happen
#include <stdio.h>
#define MAX_FILE 1000000
int readFile(char fileName[], char textStr[]);
int main(int argc, char *argv[]){
char textStr[MAX_FILE];
char cArray[27] = '\0';
if (argc != 2){
printf("Invalid number of arguments\n");
printf("Usage: %s file_name\n", argv[0]);
return 1;
}
if (readFile(argv[1], textStr) == -1) {
printf("Failed to load file\n");
return 1;
}
int i=0;
while(textStr[i]!= '\0')
{
printf("%c", textStr[i]);
i++;
}
switch(){
case 'a': case 'A':
/*code here */
}
iArray[i];
return 0;
}
int readFile(char fileName[], char textStr[])
{
FILE *fptr;
char c;
int i = 0;
if ((fptr = fopen(fileName, "r")) == NULL){
printf("Error: failed to open %s\n", fileName);
return -1;
}
while ((c = fgetc(fptr)) != EOF) {
if (i == MAX_FILE - 1)
break;
textStr[i++] = c;
}
textStr[i] = '\0';
return i;
}