C语言扫尾,文件系统【2018.3.20】

关于文件系统:

#include<stdio.h>
#include<time.h> 
int main(void)
{
//	int i;char ch;
//	FILE *fp;
//	fp=fopen("a.txt","w");		//写文件 
//	for(i=0;i<10;i++){
//		ch=getchar();
//		fputc(ch,fp);
//	}
//	fclose(fp);



//	int i;char ch;
//	FILE *fp;
//fp=open("a.txt","r");		//读文件 
//	for(i=0;i<10;i++){
//		ch=fgetc(fp);
//		putchar(ch);
//	}
//	fclose(fp);				//读文件到文件尾 



//	int i;char ch;
//	FILE *fp;				
//fp=fopen("a.txt","r");
//	ch=fgetc(fp);
//	while(ch!=EOF)
//	{
//		putchar(ch);
//		ch=fgetc(fp);
//	}
//	fclose(fp);



//FILE *stream;
//	char msg[30];
//	time_t timep;				//时间相关的结构体 
//	stream=fopen("a.txt","a+");
//	fgets(msg,30,stream);			//从文件中读取字符串 
//	printf("%s\n",msg);
//	time(&timep);
//	fputs(ctime(&timep),stream);		//在文件中写入字符串 
//	fclose(stream);



//		char ch;						
//		FILE *fp1,*fp2;
//		fp1=fopen("a.txt","r");
//		fp2=fopen("b.txt","w");
//		ch=fgetc(fp1);
//		while(!feof(fp1));				//判断文件是否结束 
//		{
//			putchar(ch);
//			ch=fgetc(fp1);
//		}
//		rewind(fp1);					//重返文件开头 
//		ch=fgetc(fp1);
//		while(!feof(fp1))
//		{
//			fputc(ch,fp2);
//			ch=fgetc(fp1);
//		}
//		fclose(fp1);
//		fclose(fp2);


//struct company				//磁盘文件上存有十家上市公司的资产负债率数据,将第四家公司的数据显示出来 
//{
//	char name[20];
//	float debt_ratio;
// };
//    struct company st;
//    FILE*fp;
//    if((fp=fopen("company.dat","rb"))==NULL)
//    {
//    	printf("cannot read file\n");
//    	return -1;
//	}
//	fseek(fp,3* sizeof(struct company),0);				//文件定位函数 
//	fread(&st,sizeof(struct company),1,fp);				//读取相应信息 
//	printf("%s\t%.2f\n",st.name,st.debt_ratio);			//输出信息 
//	fclose(fp);



FILE *stream;
stream=fopen("company.dat","w");
fgetc(stream);
if(ferror(stream))					//文件出错检测函数 
{
	printf("读company.dat文件出现错误\n");
	clearerr(stream);				//文件结束标志函数 
 }
 fclose(stream); 
	return 0;
 } 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值