I'm trying to pass a filename and go through every character in the file and create an array of 127 nodes and increment the weight of that node's element in the array based on the ASCII value of the character that was read in...But this is the error I'm getting atm:
test.c: In function âmainâ:
test.c:16: warning: initialization from incompatible pointer type
test.c: In function âcreateFreqTableâ:
test.c:25: error: request for member âweightâ in something not a structure or union
test.c:34: error: request for member âweightâ in something not a structure or union
test.c:37: warning: comparison between pointer and integer
-bash-4.1$
Here is my code:
Code:#include <stdio.h> #include <stdlib.h> typedef struct tnode { double weight; int c; struct tnode* left; struct tnode* right; struct tnode* parent; } singleNode; singleNode* createFreqTable(char* filename); int main(int argc, char *argv[]) { struct singleNode* leafNodes = createFreqTable("test.txt"); return 0; } singleNode* createFreqTable(char* filename) { singleNode *freqArray = malloc(127*sizeof(singleNode)); for(int i = 0; i < 127; i++){ *(freqArray+i).weight = 0; } FILE *f; f = fopen(filename, "r"); int temp = 0; do { temp = fgetc(f); for(int i = 0; i <= temp; i++){ if(temp == i){ *(freqArray+i).weight++; } } } while (f != EOF); fclose(f); return freqArray; }