1个回答
展开全部
#include<stdio.h>
void main()
{
FILE *f;
int i=600;
int a[10]={1,2,3,4,5,6};
int b[10]={0};
//写入文件
f=fopen("D:\\a.txt","wt");
if(f==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
printf("文件打开成功!\n");
for(i=0;i<10;i++)
fprintf(f,"%d ",a[i]);
printf("文件写入成功!\n");
}
i=fclose(f);
if(i==0)printf("文件关闭成功!\n");
else printf("文件关闭失败!\n");
//从文件中读出
f=fopen("D:\\a.txt","rt");
if(f==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
printf("文件打开成功!\n");
for(i=0;i<10;i++)
fscanf(f,"%d",&b[i]);
for(i=0;i<10;i++)
printf("%d ",b[i]);
printf("\n");
}
}
void main()
{
FILE *f;
int i=600;
int a[10]={1,2,3,4,5,6};
int b[10]={0};
//写入文件
f=fopen("D:\\a.txt","wt");
if(f==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
printf("文件打开成功!\n");
for(i=0;i<10;i++)
fprintf(f,"%d ",a[i]);
printf("文件写入成功!\n");
}
i=fclose(f);
if(i==0)printf("文件关闭成功!\n");
else printf("文件关闭失败!\n");
//从文件中读出
f=fopen("D:\\a.txt","rt");
if(f==NULL)
{
printf("文件打开失败!\n");
return;
}
else
{
printf("文件打开成功!\n");
for(i=0;i<10;i++)
fscanf(f,"%d",&b[i]);
for(i=0;i<10;i++)
printf("%d ",b[i]);
printf("\n");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询