zoukankan      html  css  js  c++  java
  • linux内核list使用demo(待调试)

    1. list.h需要拷贝到/usr/local/include, https://www.cnblogs.com/muahao/p/8109733.html 这里有个list.h可以放到该目录下

    2. 结构体中添加list_head成员

    //
    // Created by gxf on 2020/2/7.
    //

    #include <string.h>
    #include <stdio.h>
    #include <list.h>
    #include <stdlib.h>

    typedef struct {
    int age;
    struct list_head list;
    }person;

    int main(int argc, char **argv){
    person *tmp, personlist;

    INIT_LIST_HEAD(&personlist.list);
    // add
    for (int i = 0; i < 3; i++) {
    tmp = (person*) malloc(sizeof(person));
    scanf("%d", &tmp->age);
    // list_add(&(tmp->list), &(personlist.list));
    list_add_tail(&(tmp->list), &(personlist.list));
    }
    // travel
    list_for_each_entry(tmp, &personlist.list, list)
    printf("age:%d ", tmp->age);
    printf(" ");

    // update
    tmp = (person*) malloc(sizeof(person));
    tmp->age = 10;
    list_replace(&(personlist.list.next), &(tmp->list));
    tmp = NULL;
    list_for_each_entry(tmp, &personlist.list, list)
    printf("age:%d ", tmp->age);
    printf(" ");

    // delete
    list_del(personlist.list.next->next);
    list_for_each_entry(tmp, &personlist.list,list)
    printf("age:%d ", tmp->age);

    return 0;
    }

      

    CMakelist.txt

    include_directories(/usr/local/include)
    add_executable(list list-demo.c)
    

      

  • 相关阅读:
    如何在Ubuntu上安装配置和使用Docker
    在Ubuntu 20.04 LTS Focal Fossa上安装Netdata Monitoring
    CG-CTF 480小时精通C++
    IDA 动态调试
    CG-CTF 签到
    CG-CTF WxyVM
    buu 达芬奇 && ROT
    buu firmware
    buu [MRCTF2020]keyboard
    buu signin
  • 原文地址:https://www.cnblogs.com/luckygxf/p/12292995.html
Copyright © 2011-2022 走看看