Hi boys, I am working for a job interview and I was writing a nice piece of cod in c++, partially copied and pasted.

This is supposed to work but now i am obliged to use dev-c++ last version for windows, usually I just use gcc on linux and I at the compilation I receive: expected primary-expresion before "struct".

I write the first part of the code till one line after the error, I really need to have this running, I suspect it is a problem with the compiler, please help.

Thanks in advance,

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//#include "sort_words.h"
struct word_item {
	char * word;
	struct word_item * next;

struct word_list {
	int length;
	struct word_item * first_word;
	struct word_list * next;

struct word_list * first_word_list = NULL;

char * read_word(FILE * fin){
	char c;
	int i;
	char * buffer = (char *)malloc(sizeof(char));
	buffer[0] = '\0';
	for (i=0; (c = fgetc(fin))!=EOF; i++) {
		if (isspace(c) || ispunct(c))
		buffer[i] = c;
		buffer = (char *)realloc(buffer, sizeof(char)*(i+1));
		buffer[i+1] = '\0';
	if (c == EOF)
		return NULL;
	return buffer;

void init_word_list() {
	first_word_list = NULL;

struct word_list * 
init_word_list_item(int length, struct word_list * next, struct word_item * item) {
	struct word_list * word_list_item;
	word_list_item = (struct word_list *) malloc(sizeof(struct word_list));
	if (word_list_item == NULL) {
		printf("cannot allocate enough memory\n");
	word_list_item->length = length;
	word_list_item->next = next;
	word_list_item->first_word = item;
	return word_list_item;

/*void append_word_item(struct word_list * current, struct word_list * new) {
	new->next = current->next;
	current->next = new;

struct word_list * get_word_list_item(int length) {
	struct word_list * cwl = NULL;
	struct word_list * new = NULL;       // Here the error is given
	struct word_list * previous = NULL;
cross-posting - http://cboard.cprogramming.com/cplusplus-programming/123013-expected-primary-expression-before-struct.html
7 Years
Discussion Span
Last Post by doraemon79

It doesn't look like C++ code at all. And the moderators might prove that in sometime by moving it to the C forum !!


It doesn't look like C++ code at all. And the moderators might prove that in sometime by moving it to the C forum !!

you are right and this means I am terribly wrong, after what u wrote i figured out I was compiling with the option c++ checked on instead of ANSI c.
Sorry for wasting your time, it may consoulate you I wasted much more in a difficult situation.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.