Question

I am trying to build a linked list, but I'm stuck right at the beginning - I'm a complete beginner. How do I define the structure?

Here are the error messages I get:

8 8 C:\Users\user\Desktop\list_funcs.c [Error] redefinition of 'struct data_node' 4 0 C:\Users\user\Desktop\list_funcs.c In file included from list_funcs.c 3 8 C:\Users\user\Desktop\list_funcs.h [Note] originally defined here 28 C:\Users\user\Desktop\Makefile.win recipe for target 'list_funcs.o' failed

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "list_funcs.h"



  struct data_node {
char name [25];
int data;
struct data_node *next;
  };

Here's what the header file contains

#define STRINGMAX 25

struct data_node {
 char name [STRINGMAX];
 int data;
 struct data_node *next;
 };



struct data_node * insert (struct data_node **, int, char *);
Was it helpful?

Solution

Your .c file contains a definition of struct data_node, but your header file (which the .c file includes) also contains a definition of struct data_node. Drop the definition from the .c file and you should be fine.

OTHER TIPS

The error itself says "redefinition of 'struct' ". you have declared struct data_node twice ..one in header file and the other in .c file. you can drop one of them. If you want to use header file then drop the one in .c file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top