关于文件系统:
#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;
}