I'm trying to write a C concordance program that reads words in from a file, strips them of non-alphanumeric characters, counts the number of times they occur, and prints them out, sorted and formatted, to a file containing the word and it's corresponding count in the text.
I'm running into this compiler error and I cannot figure out what the issue is, especially since it has no problem with the node *top in the previous method signature...
The error I'm getting is:
proj1f.h:12: error: syntax error before "FILE"
.h
file:
#ifndef PROJ1F_H
#define PROJ1F_H
typedef struct node {
char *data;
struct node *left;
struct node *right;
} node;
void insert(char *x, node *top, int count);
void print(node *top, FILE *file, int *count, int index);
#endif
functions .c file
#include "proj1f.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void insert(char *x, node *top, int count){
if(top == NULL){ //place to insert
node *p = malloc(sizeof(node));
p -> data = x;
p -> left = p-> right = NULL;
top = p;
count++;
}
else if(x == top -> data)
count++;
else if(x < top -> data)
insert(x, top -> left, count);
else //x > top -> data;
insert(x, top -> right, count);
}
void print(node *top, FILE *file, int *count, int index){
if(top == NULL)
fprintf(file, "%s", "no input read in from file");
else{
print(top -> left, file, count, index++);
fprintf(file, "%-17s %d\n", top -> data, count[index]);
print(top -> right, file, count, index++);
}
}
Main .c
file
#include "proj1f.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char *argv[]) {
int count[300];
int index = 0;
int wordInFile = 0;
node *root = NULL;
FILE * readFile = fopen(argv[1], "r");
while(feof(readFile)) {
char word[30];
char fword[30];
fscanf(readFile, "%s", word);
//format word
int findex = 0;
int i;
for(i = 0; i < strlen(word); i++) {
if(isalnum(word[i])) {
fword[findex] = word[i];
findex++;
} else if(word[i] == NULL) {
fword[findex] = word[i];
break;
}
}
//insert into tree
insert(fword, root, count[wordInFile]);
wordInFile++;
}
fclose(readFile);
FILE *writeFile = fopen(argv[2], "w+");
print(root, writeFile, count, index);
fclose(writeFile);
return 0;
}
Any help would be appreciated.