François Richard
François Richard

Reputation: 7045

Display recursive struct in c

    idx x, z ;
    for (x = 0 ; x < k ; ++x) { 
        if (mots[x].mot) { 
            printf("%s :", mots[x].mot) ;
            //Below not working properly how to write all my refs ?
            // printf("%i ", mots[x].refs -> cdr ->ref);
            // while (mots[x].refs -> cdr) printf("%i ", mots[x].refs -> ref); 
            printf("\n") ; 

How to iterate properly on my struct in order to display each refs of mots[x] ?

I hope the problem is clear enough, thanks in advance

Upvotes: 1

Views: 55

Answers (1)

kaylum
kaylum

Reputation: 14044

if (mots[x].mot) { 
    printf("%s :", mots[x].mot) ;
    struct node *node = mots[x].refs;
    while (node) {
         printf("%i ", node->ref);
         node = node->cdr;
    }
    printf("\n");
}

Upvotes: 1

Related Questions