我用vim编写了一个文件读取的程序,读取的文件在同一个文件夹,程序运行时出现段错误,而且执行后读取的文件里面的内容没有了,不知道是怎么回事,希望那个人帮忙指点一下
我的源程序是
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE* fp;
char line[101];
if((fp=open("example1_1","r"))==NULL)
{
printf("file cannot be open\n");
exit(1);
}
while(fgets(line,100,fp)!=NULL)
printf("%s",line);
close(fp);
return 1;
}
在此先谢谢给予指点我的朋友
求助一个问题
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
-
- 帖子: 7
- 注册时间: 2008-11-17 14:33
Re: 求助一个问题
#include<iostream>
FILE *fin,*fout;
int main(void){
fin=fopen("输入文件","r");
fout=fopen("输出文件","w");
内容
fclose(fin);
fclose(fout);
return 0;
}
FILE *fin,*fout;
int main(void){
fin=fopen("输入文件","r");
fout=fopen("输出文件","w");
内容
fclose(fin);
fclose(fout);
return 0;
}
- CLOCKWORKHEART
- 帖子: 635
- 注册时间: 2007-11-05 19:26
Re: 求助一个问题
代码: 全选
char line[101];
if((fp=open("example1_1","r"))==NULL)
{
fopen是C标准函数库,返回FILE结构的指针变量。
如2楼所说,各自成套使用。
Everything that has a beginning has an end.