<div dir="ltr"><div>I have a linked list like this <a href="http://pastebin.com/bwF3jLb6">http://pastebin.com/bwF3jLb6</a> . The problem i am facing is i have initialized the list head and</div><div>Â then i am doing malloc for that struct object. What i need is i want to make struct abc_st *r as head of linked list and other nodes after it.</div><div><br></div><div>typedef struct abc {</div><div><span class="" style="white-space:pre"> </span>char client_id[18];</div><div>Â Â char mac[18];</div><div>Â Â st_list_head list;</div><div>}abc_st;</div><div><br></div><div>abc_st* check_fields (abc_st *ptr)</div><div>{</div><div>Â Â char cmd[500];</div><div>Â Â MYSQL_RES *result;</div><div>Â Â MYSQL_ROW row;</div><div>Â Â int num_rows;</div><div>Â Â abc_st *r=NULL,*temp=NULL;</div><div>Â Â INIT_LIST_HEAD(&r->list); Â // i have intialized the head here</div><div><br></div><div>Â Â sprintf(cmd, "SELECT * FROM ABCD_TABLE WHERE MAC = %.4x", ptr->mac);</div><div>Â Â Â Â /* Running the sql query to check for fields with value in database */</div><div>Â Â if (mysql_query(abc_db.db_handle, cmd)) {</div><div>Â Â Â Â num_rows = -1;</div><div>Â Â Â Â goto done;</div><div>Â Â }</div><div>Â Â result = mysql_store_result(abc_db.db_handle);</div><div>Â Â if (result == NULL) {</div><div>Â Â Â Â num_rows = -1;</div><div>Â Â Â Â goto done;</div><div>Â Â }</div><div>Â Â num_rows = mysql_num_rows(result);</div><div><br></div><div>Â Â while ((row = mysql_fetch_row(result)))</div><div>Â Â {</div><div>Â Â Â Â r= (abc_st *)malloc(sizeof(abc_st));</div><div>Â Â Â Â memcpy(r->mac,row[1],strlen(row[1])+1);</div><div>Â Â Â Â memcpy(r->client_id,row[0],strlen(row[0])+1);</div><div>How should i use list_add ?</div><div>Â Â Â Â //list_add(struct list_head *new, struct list_head *head) Â //prototype of list_add</div><div>Â Â Â Â // list_add(&temp->list,&r->list); Â //it will go wrong here, i want to make r(structure r as head and then add other strutcure objects) Â </div><div>Â Â Â // Â r->link = NULL;</div><div>Â Â Â Â //list_add(r, ptr);</div><div><br></div><div>Â Â }</div><div>done:</div><div>Â Â mysql_free_result(result);</div><div><br></div><div>Â Â return r;</div><div><br></div><div>}</div><div><br></div></div>