linked list problem

Discussion in 'C Programming' started by Darius Fatakia, Nov 12, 2003.

  1. 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;
    }
    }
    Darius Fatakia, Nov 12, 2003
    #1
    1. Advertising

  2. In article <bosbob$t2n$>,
    Darius Fatakia <> 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 <>
    Rouben Rostamian, Nov 12, 2003
    #2
    1. Advertising

  3. Thanks!!!
    Darius Fatakia, Nov 12, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ritchey
    Replies:
    7
    Views:
    479
    emerth
    Jul 10, 2003
  2. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    467
    emerth
    Jul 10, 2003
  3. fool
    Replies:
    14
    Views:
    506
    Barry Schwarz
    Jul 3, 2006
  4. joshd
    Replies:
    12
    Views:
    668
    John Carson
    Oct 2, 2006
  5. jawdoc
    Replies:
    9
    Views:
    752
    Chris Thomasson
    Mar 10, 2008
Loading...

Share This Page