Simple use of the sglib library in C language programming

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.