#include
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");
}
}