linux程序设计基础——概述,Linux程序设计基础—C环境.doc

Linux程序设计基础—C环境.doc

Linux程序设计基础—C环境

一 VI编辑器的使用

使用VI编辑下列几个函数文件:

hello.h

starfun.h

hello.c

star.c

Starfun.h 文件内容如下:

/*****starfun.h*****/

#ifndef STARFUN_H

#define STARFUN_H

#define NUM 4

#define NUMBER 3

int star1() {

int i,j,k;

for(k=1;k<=NUM;++k) {

for(i=1;i<=(NUM-k);++i)

printf(" ");

for(j=1;j<=(2*k-1);++j)

printf("*");

printf("\n");

}

return 0;

}

int star2() {

int i,j,k;

for(k=NUMBER;k>=0;--k) {

for(i=1;i<=(NUMBER-k+1);++i)

printf(" ");

for(j=1;j<=(2*k-1);++j)

printf("*");

printf("\n");

}

return 0;

}

#endif

hello.h文件内容如下:

/*hello.h*/

#ifndef HELLO_H

#define HELLO_H

void hello() {

star1();

printf("hello,my friends\n");

}

#endif

hello.c 文件内容如下:

void showhello() {

hello();

}

star.c文件内容如下:

#include "starfun.h"

#include "hello.h"

#include

int main() {

star1();

star2();

showhello();

return 0;

}

Vi编辑器的使用,可以参考PPT,在使用Vi编辑器的过程中,注意使用Vi的单行和多行复制命令,练习字符串查找替换命令,删除一个字符,删除光标后整个内容命令,删除一行命令,恢复删除,保存和退出命令等命令,并尝试使用其他命令。掌握

#ifndef STARFUN_H

#define STARFUN_H

的宏定义用法

二.使用gcc编译器,编译程序

第一种方法:分步进行

1.由star.c starfun.h 文件生成star.o 目标文件

gcc -c star.c -o star.o

2.由hello.c hello.h starfun.h生成hello.o目标文件

gcc -c hello.c -o hello.o

3.由hello.o star.o 生成应用程序myprog

gcc star.o hello.o -o myprog

[root@localhost 01_hello]# ./myprog

*

***

*****

*******

*****

***

*

*

***

*****

*******

hello,my friends

第二种方法:一条命令完成以上操作

gcc star.c hello.c -o myprog

结合本次课的PPT关于gcc部分,体会gcc编译器编译的过程,并在实验报告中描述

在以上编译中尝试

[root@localhost 01_hello]# gcc star.c hello.c -o myprog

[root@localhost 01_hello]# gcc -w star.c hello.c -o myprog

[root@localhost 01_hello]# gcc -Wall star.c hello.c -o myprog

In file included from star.c:1:

starfun.h: In function `star1':

starfun.h:13: warning: implicit declaration of function `printf'

star.c: In function `main':

star.c:8: warning: implicit declaration of function `showhello'

hello.c: In function `showhello':

hello.c:4: warning: implicit declaration of function `hello'

体会-Wll -w选项的作用

查阅当前的gcc版本命令

[root@localhost 01_h

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值