Hi all. I am stumped by the warnings and errors for the "countwords" function.
// wordcount.c: count the number of occurrences of every word in a text file
// 4 functions: openfile, countwords, sort, display
#define FILENAMELENGTH 30
#define SUCCESS 1
#define FAILURE 0
int openfile(char *filename);
void sort(char *filename);
void display(char *filename);
printf("Enter file to open: ");
fgets(filename, FILENAMELENGTH, stdin);
filename[strlen(filename) - 1] = '\0';
} while((result = openfile(filename)) == FAILURE);
int openfile(char *filename)
if((file = fopen(filename, "r")) == NULL)
printf("%s opened successfully", filename);
#define WORDLENGTH 30
int c, count;
int wordcount = 0;
while((c = fgetc(file)) != EOF)
if((c != '.') && (c != ',') && (c != '!') && (c != "") && (c != ':')) //if c is not a space or punctuation, add c to buffer
buffer[count] = c;
buffer[count++] = '\n'; // if c is a space or punctuation, add terminator to create string
array[count].word = malloc((count) * sizeof(char)); // allocate memory for string
*array[count].word = buffer[count]; // assign string to pointer in structure
array[count].wordcount++; // increment counter for word
void sort(char *filename)
void display(char *filename)
1. What does it mean by expected ; etc in line 59? I can't see any missing punctuation.
|In function ‘countwords’:|
59|error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token|
64|warning: comparison between pointer and integer [enabled by default]|
64|warning: comparison with string literal results in unspecified behaviour [-Waddress]|
75|error: ‘struct word’ has no member named ‘wordcount’|
||=== Build finished: 2 errors, 2 warnings ===|
2. For line 64, fgetc returns an integer, and I am comparing it with characters(which are integers), so why does it mention pointer?
3. Also, for line 65, "string literal" means "", right? When I use ' ', I get an error message "empty character constant". I just want to compare c to empty white space.
4. There is a "wordcount" member in the struct, so why the error message?
Thanks in advance.