I have to write a program for my C programming class that takes a text file outlining the Letter Frequency, and then use that information to take another text file input that is encrypted and decrypt it using that letter frequency. At first, I didn't really know how to start... so I decided to start throwing all of my thoughts into a main function and just trying to get it to work from there, but I feel like I'm doing this in such a convoluted manner and now I'm at the point where I just wanted to test to see if used the concept of structures right by outputting an array of structures on screen with all of my information, but I'm getting an error: Line 43 --> Subscripted Value is Neither Array nor Pointer.
I've never seen such an error before and I'm not really sure what it means... I was hoping I could show you what I have so far and perhaps someone could explain this error to me and give me some advice on how I should proceed in writing this code (advice and explanations please as it's detrimental that I learn the material ^_^).
Here is my code:
struct keyFreq
{
char letter;
float freq;
};
int main()
{
FILE *fin;
char freqname[20];
char derp;
char temp[6];
int spacecounter = 0;
printf("What is the name of the frequency file? ");
scanf("%s", freqname);
fin = fopen(freqname, "r");
struct keyFreq k[25];
while(!feof(fin)) {
fscanf(fin, "%c", &derp);
int i;
for(i = 0; i < 26; ++i) {
if((isalpha(derp)) && k[i].letter == NULL) {
k[i].letter = derp;
break;
}
if((isadigit(derp)) || derp == '.') {
int j;
for(j = 0; j < 7; ++j) {
if(temp[j] == -1)
temp[j] = derp;
}
break;
}
if((isspace(derp)) && (k[i].freq == '\0') && (spacecounter >= 2)) {
double now;
int k;
now = atof(temp);
for(k = 0; k < 7; ++k)
temp[k] = -1;
k[i].freq = now; //Problematic Line <--
spacecounter = 0;
break;
}
if((isspace(derp)) && spacecounter < 2)
spacecounter = spacecounter + 1;
}
}
return 0;
}