5 Star 0 Fork 1

冉余/tcp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
list.c 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
冉余 提交于 2014-04-12 14:15 . pthread msg
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
const int N = 10;
struct user {
int id;
struct list_head list;
};
int main(void) {
LIST_HEAD(user_queue);
struct user *tmp;
struct list_head *pos;
struct list_head *a[N];
int i;
for (i = 0; i < N; i++) {
tmp = malloc(sizeof(struct user));
//printf("Please enter user id:");
//scanf("%d", &tmp -> id);
tmp -> id = i+1;
a[i] = &(tmp -> list);
list_add_tail(a[i], &user_queue);
}
printf("\n");
printf("list using list_for_each()\n");
list_for_each(pos, &user_queue){
tmp = list_entry(pos, struct user, list);
printf("id= %d\n", tmp -> id);
}
printf("\n");
printf("list using list_for_each_entry()\n");
list_for_each_entry(tmp, &user_queue, list){
printf("id= %d\n", tmp -> id);
}
printf("\n");
printf("please enter a number you want to delete:\n");
scanf("%d", &i);
list_del(a[i-1]);
list_for_each(pos, &user_queue){
tmp = list_entry(pos, struct user, list);
printf("id= %d\n", tmp -> id);
}
free(tmp);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/exileduyi/tcp.git
git@gitee.com:exileduyi/tcp.git
exileduyi
tcp
tcp
master

搜索帮助