主题:c语言文件的操作
#include <stdio.h>
#include "stdlib.h"
void main()
{
FILE *fp,*fp2;
int a[10],b,i,f;
fp=fopen("1.txt","rb");
if(fp==NULL)
{printf("file open error.\n");
exit(0);
}
i=0;
while(!feof(fp)&&i<10)
{
fscanf(fp,"%d",&a[i]);
i++;
}
//for(i=0;i<10;i++)
//printf("%4d",a[i]);
printf("请输入查找的 数据 \n");
scanf("%d",&b);
for(i=0;i<10;i++)
{
if(a[i]==b) {f=i;break;}
}
if(i==10) f=0;
fp2=fopen("2.txt","wb");
if(fp2==NULL)
{printf("file open error.\n");
exit(0);
}
fprintf(fp2,"%4d",f);
fclose(fp);
fclose(fp2);
} //为什么在移动硬盘中不能执行呢?
#include "stdlib.h"
void main()
{
FILE *fp,*fp2;
int a[10],b,i,f;
fp=fopen("1.txt","rb");
if(fp==NULL)
{printf("file open error.\n");
exit(0);
}
i=0;
while(!feof(fp)&&i<10)
{
fscanf(fp,"%d",&a[i]);
i++;
}
//for(i=0;i<10;i++)
//printf("%4d",a[i]);
printf("请输入查找的 数据 \n");
scanf("%d",&b);
for(i=0;i<10;i++)
{
if(a[i]==b) {f=i;break;}
}
if(i==10) f=0;
fp2=fopen("2.txt","wb");
if(fp2==NULL)
{printf("file open error.\n");
exit(0);
}
fprintf(fp2,"%4d",f);
fclose(fp);
fclose(fp2);
} //为什么在移动硬盘中不能执行呢?