include <stdio.h>
include <stdlib.h>
int main (void)
{
FILE * fp;
int a[10];
int max=0;
int i;
if ((fp=fopen("d:lvyanfeng.txt","a+"))==NULL)
{
printf("File open error!
");
exit(0);
}
for(i=0;i<5;i++)
fscanf(fp,"%d",&a[i]);
for(i=1;i<5;i++){
if(a[i]>a[max])
max=i;
}
printf("%d %d",a[max],max);
fprintf(fp,"
%d %d",a[max],max);
if (fclose(fp)){
printf ("Can not close the file!
");
exit (0);
}
return 0;
}
流程:
错误截图:
正确截图: