What is wrong?

P

Profetas

#include <stdio.h>

typedef enum {FALSE=0, TRUE=1} boolean;

typedef struct {
boolean base[16];
unsigned int fitness;
}individual;


typedef struct{
individual first;
individual second;
}pair;


struct node{
individual member;
struct node* next;
}
typedef struct node Node;

int main(){

printf("teste\n");

return(0);
}


it gives the following error
combine.c:21: two or more data types in declaration of `Node'
 
C

Chris Torek

struct node{
individual member;
struct node* next;
}
typedef struct node Node;

Besides the (correct) answers already posted about the semicolon,
I suggest writing the typedef *first*. (Actually, I prefer to
avoid typedef as much as possible, but I assume you have some strong
preference for them.) If you put the typedef first, take a look
at the result:

typedef struct node Node;
struct node {
individual member;
Node *next;
};

You can now use the typedef inside the structure definition. This
allows you to be consistent -- to use "Node" everywhere, instead
of "struct node *" in one special case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top