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,
Dora

#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))
			break;
		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");
		exit(-1);
	}
	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;

You probably compiled it as C++, where new is a reserved word.

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

Before I say something, what do you think this statement is doing :

struct word_list * new = NULL;

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.