一,先上头文件:linklist.h
需要在头文件中声明 “链表操作函数”。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define LEN sizeof(struct Node)
#define OK 0
#define ERROR 1
typedef struct Node
{
uint8_t id;
uint32_t mac;
struct Node *next;
}Node;
typedef struct Node *LinkList;
LinkList CreateEmptyLinkList(void);
LinkList AddNode(LinkList , int);
int DelNodeByID(LinkList, uint8_t, uint32_t);
int UpdateNodeByID(LinkList, uint8_t, uint32_t);
int FindNodeByID(LinkList, uint8_t, uint32_t);
int PrintList(LinkList);
二,
1,链表操作程序文件:linklist.c
#include "linklist.h"
int n; //number of all nodes
/* create empty linklist */
LinkList CreateEmptyLinkList()
{
LinkList head;
n = 0;
head = (LinkList)malloc(LEN);
if(head==NULL)
{
perror("Create linklist failed! try again");
return NULL;
}
head->id = 0xf;
head->mac = 0;
head->next = NULL;
return head;
}
/* add node to the head of linklist */
LinkList AddNode(LinkList L, int m) //add m nodes
{
LinkList p;
int flag = 0;
int i;
uint8_t id;
uint32_t mac;
for(i=0; i<m; i++)
{
LinkList q = L;
p = (LinkList)malloc(LEN);
printf("Input ID:\n");
scanf("%hhu",&id);
getchar();
printf("check ok\n");
printf("Input MAC:\n");
scanf("%u",&mac);
printf("check ok\n");
do{
if((id == q->id)

本文介绍如何使用Makefile管理一个包含链表增删改查操作的C语言小项目。首先展示了linklist.h头文件中声明的链表操作函数,接着详细讲解了linklist.c链表操作程序和test.c测试程序的实现。最后,通过Makefile实现项目的自动化编译和测试,总结了项目管理的经验。

452

被折叠的 条评论
为什么被折叠?



