linked list problem

D

Darius Fatakia

It's been a while since I programmed in C, and I'm confused as to why I get
the following error message (why aren't they both "pointer to struct
chromT{}"?:

"genet.c", line 192: warning: assignment type mismatch:
pointer to struct {double score, enum {worst(2), mid(1), best(0)}
cat, array[10] of pointer to struct geneT {..} genes, pointer to struct
chromT {..} next} "=" pointer to struct chromT {}

my code is as follows (I have noted the line with the problem):

// DATA STRUCTURES

typedef struct {
double score;
categ cat;
struct geneT *genes[GENES_PER_CHROM];
struct chromT *next;
} chromT;

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;


// FUNCTION PROTOTYPES
static void *LLGo (chromT *start, int n);



/* LLGo
*
* This function returns the address of the "n-th" element
* in the linked list.
*/
static void *LLGo (chromT *start, int n) {
int i = 0;
chromT *cursor = start;

while((cursor->next != NULL) && (i < n)) {
cursor = cursor->next; // THIS IS THE LINE WITH THE PROBLEM
i++;
}
if(i < n) {
return NULL;
}
else {
return cursor;
}
}
 
R

Rouben Rostamian

It's been a while since I programmed in C, and I'm confused as to why I get
the following error message (why aren't they both "pointer to struct
chromT{}"?:

"genet.c", line 192: warning: assignment type mismatch:
pointer to struct {double score, enum {worst(2), mid(1), best(0)}
cat, array[10] of pointer to struct geneT {..} genes, pointer to struct
chromT {..} next} "=" pointer to struct chromT {}

my code is as follows (I have noted the line with the problem):

// DATA STRUCTURES

typedef struct {
double score;
categ cat;
struct geneT *genes[GENES_PER_CHROM];
struct chromT *next;
} chromT;

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;

In the first typedef:

you refer to "struct geneT", but you haven't defined a "struct geneT".
you refer to "struct chromT", but you haven't defined a "struct chromT".

Try this:

typedef struct {
double x[PTS_PER_FEAT];
double id; // something to keep track of each feature.
} geneT;

typedef struct chromT { // note: struct chromT
double score;
categ cat;
geneT *genes[GENES_PER_CHROM]; // note: "geneT", not "struct geneT"
struct chromT *next;
} chromT;
 

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

Similar Threads

Linked-list problem - compiles but segfaults 13
Reversing a linked list 116
linked list 26
Statically declare a constant linked list 9
linked list example 34
linked list 19
Singly Linked List in C 62
Newbie: Linked list 2

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top