I created a code to identify different objects, each contained in a link. So far, so good, here is the code:
Code:
#include <stdio.h>
typedef struct object {
int a;
int b;
} an_object;
typedef struct link {
an_object * infos;
struct link * next;
} an_link;
an_link *addElement(an_link *the_link, an_object *l_object) {
an_link *new_link = malloc(sizeof(un_link));
new_link->next = NULL;
new_link->infos = malloc(sizeof(an_object));
new_link->infos->a = l_object->a;
new_link->infos->b = l_object->b;
if (the_link== NULL)
return new_link;
else {
an_link *link_common = the_link;
while (link_common->next != NULL)
link_common= link_common->next;
link_common->next = new_link;
return the_link;
}
}
int main(void)
{
an_link*the_link= NULL;
an_object l_object = { 12, 56 };
the_link = addElement(the_link, &l_object);
printf("%d\t%d", the_link->infos->a, the_link->infos->b);
return 0;
}
But it imposes on me to include in my list Code structure further defined as:
Code:
struct list{
an_link * premier_link;
an_link * last_link;
an_link * link_common;
};
I tried to implement the code above this structure and the changes it entails, but curiously, I do not succeed ... Can you show me please?
Bookmarks