By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

linked list problem

P: n/a
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;
}
}
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <bo**********@news.Stanford.EDU>,
Darius Fatakia <da************@yahoo.com> wrote:
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;
--
Rouben Rostamian <ro*******@umbc.edu>
Nov 13 '05 #2

P: n/a
Thanks!!!
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.