c - Syntax error in method signature in .h file -
i'm trying write c concordance program reads words in file, strips them of non-alphanumeric characters, counts number of times occur, , prints them out, sorted , formatted, file containing word , it's corresponding count in text.
i'm running compiler error , cannot figure out issue is, since has no problem node *top in 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 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 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; < strlen(word); i++) { if(isalnum(word[i])) { fword[findex] = word[i]; findex++; } else if(word[i] == null) { fword[findex] = word[i]; break; } } //insert 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 appreciated.
you're including project header before <stdio.h>
, file
type isn't defined yet.
you need either include <stdio.h>
project header, or include project header after <stdio.h>
.
Comments
Post a Comment