使用Makefile管理一个小项目:链表的增删改查操作和测试程序

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

一,先上头文件: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) || (mac == q->mac))
				flag++;
			q = q->next;
		}while(q != NULL);

		if(!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值