LINUX大作业(北邮信息工程2024年春)(3)

2025-09-09

`

;; *) sign=1 continue ;; esac done exit 1

fi #if 5, make sure if the user wanna overwrite the file that has been created. cp $1 $2 if [ \then

echo \else

echo \fi #if 6, to check if there's sth wrong.

2.Makefile与C编程:本题考查Makefile的编写,C语言基础,以及编程规范性。编写C程序,完成单向链表反转功能,如:输入字符串Hello World,每个链表节点仅保存一个字符,最后将整个单向链表的顺序反转,并返回链表头指针。 要求:(1)建立四个文件:main.c reverse.c reverse.h Makefile; (2)main.c仅包含main()函数,负责输入字符串,调用反转函数; (3)在合适的文件中声明你的数据结构,对函数进行声明; (4)在合适的文件中存储反转函数的实现;

(5)编写Makefile,并使用GCC通过Makefile对你写的程序实现编译,连接,形成最终可以执行的文件。

-------------------------------------------

main.c文件 -------

#include \

#include \#include \

char main(void)

{char *i;

NODE *head,*p,*q;

head=NULL;

printf(\

`

for(i=1;i<=n;i++) {

p=(NODE *)malloc(sizeof(NODE)); p->;data=i; if(head==NULL) q=head=p; else{ q->;next=p; q=p; } }

q->;next=NULL;

for(p=head;p;p=p->;next) p=f(head);

printf(\return 0;

} ------ reverse.c -------

#include \

NODE *f(NODE *head) {

NODE *p,*q; NODE *h; h=NULL;

for(q=head,p=head->;next;p;q=p,p=p->;next) {

if(h==NULL){ h=q;

h->;next=NULL; } else{

`

q->;next=h; h=q; } }

q->;next=h; h=q; return h;

} ---------- reverse.h ----------

typedef struct NODE { char data;

struct NODE *next;

}NODE; --------- Makefile ---------

edit: main.o reverse.o cc -o edit main.o reverse.o

main.o : main.c reverse.h cc -c main.c

reverse.o : reverse.c reverse.h cc -c reverse.c

clean:

rm edit main.o reverse.o


LINUX大作业(北邮信息工程2024年春)(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:江南大学高分子化学

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219