Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > linked list problem

Reply
Thread Tools

linked list problem

 
 
Darius Fatakia
Guest
Posts: n/a
 
      11-12-2003
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;
}
}


 
Reply With Quote
 
 
 
 
Rouben Rostamian
Guest
Posts: n/a
 
      11-12-2003
In article <bosbob$t2n$(E-Mail Removed)>,
Darius Fatakia <(E-Mail Removed)> 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 <(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Darius Fatakia
Guest
Posts: n/a
 
      11-12-2003
Thanks!!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Airplane Program with Linked Lists. The linked list portion is veryconfusing to me. jawdoc C++ 9 03-10-2008 03:38 AM
Linked list within a linked list joshd C++ 12 10-02-2006 08:57 AM
Linked list, New try (was:Linked list, no out put,help) fool C Programming 14 07-03-2006 12:29 AM
Generating a char* from a linked list of linked lists Chris Ritchey C++ 7 07-10-2003 10:12 PM
Generating a char* from a linked list of linked lists Chris Ritchey C Programming 7 07-10-2003 10:12 PM



Advertisments