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;