double_space的程序编译不了,不知道错在哪里

Hyacinthus_M 发布于 2012/12/14 16:54
阅读 104
收藏 0

dbl_space.c内容如下:

#include<stdio.h>
#include<stdlib.h>


void double_space(FILE *,FILE *);
void prn_info(char *);


int main(int argc,char **argv)
{
FILE *ifp,*ofp;


if(argc!=3){
prn_info(argv[0]);
exit(1);
}
ifp=fopen(argv[1],"r");
ofp=fopen(argv[2],"w+");
double_space(ifp,ofp);
fclose(ifp);
fclose(ofp);
return 0;
}
void double_sapce(FILE *ifp,FILE *ofp)
{
int c=0;
c=getc(ifp);

while((c=getc(ifp))!=EOF){
putc(c,ofp);
if(c=='\n')
putc('\n',ofp); //found a new line
}
}

void prn_info(char *pgm_name)
{
printf("\n%s%s%s\n\n%s%s\n\n",
"Usage: ",pgm_name, "  infile outfile",
"The contents of infile will be double-spaced",
"and written to outfile.");
}

在VIM里gcc -c dbl_space.c产生dbl_space.o文件

但是gcc -o dbl_space dbl_space.o 却产生如下错误:

[xushangmingAdmin@Hyacinthus-MS TestC]$ vim
[xushangmingAdmin@Hyacinthus-MS TestC]$ gcc -o dbl_space dbl_space.c
/tmp/ccR6ZYxV.o: In function `main':
dbl_space.c:(.text+0x70): undefined reference to `double_space'
collect2: error: ld returned 1 exit status
[xushangmingAdmin@Hyacinthus-MS TestC]$ 

另外有一个infile的文本作为输入,一个outfile的空白文件又做将infile的内容写入。

到底是哪里不对呢?本小白才刚学不久。求帮下。





加载中
返回顶部
顶部