To be honest, I haven't written a program in c language for a long time since I graduated from college. Generally, c ++ and c ++ stl and boost are used. These code libraries greatly simplify our programming complexity. Recently, for some reason, I started to write programs in c. I am a lazy person and prefer to use third-party libraries of others. It is hard to find an open-source library named sglib. Of course, I need to use it. Not much.
# Include <stdio. h> # include <stdlib. h> # include <malloc. h> # include "sglib. h "typedef struct _ ip_mask_map {int first; int second; struct _ ip_mask_map * next;} ip_mask_map, * pip_mask_map; int ipcomp (ip_mask_map * elem1, ip_mask_map * elem2) {if (elem1-> first = elem2-> first) & (elem1-> second = elem2-> second) {return 0 ;} else {return 1 ;}} int main (int argc, char * argv []) {ip_mask_map * elem, * head = NULL, * _ m Ember; elem = (pip_mask_map) malloc (sizeof (ip_mask_map); elem-> first = 1; elem-> second = 100; elem-> next = NULL; // Add elem to the linked list. If the pointer head pointing to the linked list is empty, assign the new element elem to head SGLIB_LIST_CONCAT (ip_mask_map, head, elem, next); elem = (pip_mask_map) malloc (sizeof (ip_mask_map); elem-> first = 2; elem-> second = 200; elem-> next = NULL; SGLIB_LIST_CONCAT (ip_mask_map, head, elem, next ); elem = (pip_mask_map) malloc (sizeof (ip_mask _ Map); elem-> first = 2; elem-> second = 200; elem-> next = NULL; // if the member already exists in the linked list, _ member: returns the pointer to the member. Otherwise, NULL SGLIB_LIST_ADD_IF_NOT_MEMBER (ip_mask_map, head, elem, ipcomp, next, _ member) is returned. if (_ member! = NULL) free (elem); // traverses and deletes dynamically allocated memory for (elem = head; elem! = NULL;) {pip_mask_map tmp = elem; printf ("% d, % d \ n", elem-> first, elem-> second); elem = elem-> next; free (tmp);} return 0 ;}