Linux C语言编程

Linux C语言编程

任务要求

  1. 基于Ubuntu或OpenEuler完成下面的任务(OpenEuler有加分)
  2. 选择教材第二章的一节进行编程基础练习(2.10,2.11,2.12,2.13,2.14任选一个)
  3. 建立自己的项目目录,包含自己学号信息(如20190100linkedlist),构建项目结构(src, include,bin, lib, docs, test...),然后把相应代码和文档放置到正确位置,用tree命令查看项目结构,提交截图(5分)
  4. 进行gcc相关练习(ESc, iso, -I等)提交相关截图(5分)
  5. 进行静态库,动态库制作和调用练习,提交相关截图(5分)
  6. 进行gdb相关练习,至少包含四种断点的设置,提交相关截图(10分)
  7. 编写makefile(5分)

程序编写

  • 我选择树的遍历C程序的编程练习

"insert.h"

    struct node *insert(struct node *node,int key);

"newnode.h"

   #ifndef NEWNODE_H
#define NEWNODE_h
struct node{
	int key;
	struct node *left,*right;
};
struct node *new_node(int key);
#endif

"insert.c"

#include "newnode.h"
#include "insert.h"
#include<stdio.h>
struct node *insert(struct node *node,int key)
{
	if(node==NULL)
		return new_node(key);
	if(key<node->key)
		node->left = insert(node->left,key);
	else if(key>node->key)
		node->right = insert(node->right,key);
	return node;
}

"newnode.c"

#include "newnode.h"
#include<stdio.h>
#include<stdlib.h>
struct node *new_node(int key)
{
	struct node *point = (struct node*)malloc(sizeof(struct node));
	point->key=key;
	point->left=point->right=NULL;
	return point;
}

"main.c"

#include<stdio.h>
#include "insert.h"
#include "newnode.h"

void output(struct node *root){
	if(root!=NULL)
	{
	printf("%d ",root->key);
	output(root->left);
	output(root->right);
	}
}

int main(){
int nodeValue[7]={56,23,34,27,30,47,86};
int i;
struct node *root = NULL;
root = insert(root,nodeValue[0]);
for(i=1;i<7;i++)
	insert(root,nodeValue[i]);
struct node *tree=root;
output(tree);
return 0;
}

2.建立自己的项目目录,包含自己学号信息(如20190100linkedlist),构建项目结构(src, include,bin, lib, docs, test...)

3.gcc相关练习

4.静态库

5.动态库

6.gdb相关练习
断点设置
b 函数名 设置函数断点
b 行数 设置行断点
b 行数 if i==2 设置条件断点
tb 函数 设置临时断点
调试
r 运行
s 单步运行
n 单步运行 跳过函数内断点

6、编写makefile

原文地址:https://www.cnblogs.com/kevin-hw/p/15340261.html