Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

File IO & structs

$
0
0
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:14: error: incompatible types when initializing type âstruct tnode *â using type âsingleNodeâ
test.c: At top level:
test.c:20: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âcreateFreqTableâ
-bash-4.1$


Any assistance on how to fix this would be greatly appreciated!

	typedef struct tnode {
	double weight;
	int c;
	struct tnode* left;
	struct tnode* right;
	struct tnode* parent;
} singleNode;

   singleNode createFreqTable(char* filename);

int main(){
  
   struct tnode* leafNodes = createFreqTable("test.txt");

}

node createFreqTable(char* filename) {
		singleNode freqArray[127];
		FILE *f;
		f = fopen(filename, "r");
		int temp = 0;
		do {
			temp = fgetc(f);
			for(int i = 0; i < temp; i++){
				if(temp == i){
					if(freqArray[i].weight == NULL){
						freqArray[i].weight = 1;
					}
					else{
					freqArray[i].weight++;
					}
				}
			} 
		} while (f != EOF);
	fclose(f);
	return freqArray;
}

Viewing all articles
Browse latest Browse all 51036