1、实验代码
include<stdio.h>
include<stdlib.h>
int main()
{
FILE *fp;
char sz[10];
int i,max=0,n;
if((fp=fopen("D:\sakura.txt","a+"))==NULL)
{
printf("没有该文件!
");
exit(0);
}
fscanf(fp,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(fp,"%d ",&sz[i]);
}
for(i=0;i<n;i++)
{
if(sz [i] >sz [max])
max=i;
}
fprintf("
%d %d", sz [max],max);
if(fclose(fp)){
printf("文件关不了啊!
");
exit(0);
}
return 0;
}
2、设计思路
3、实验中的问题与解决方案
问题:编译错误。
方案:一个代码打错了。
问题:数据读取不到。
方案:多次尝试后,是fscanf(fp)内的变量用错了。
问题:编写了很久很久,都懂了,但不熟练,有些细节只知道是这么用,具体说的话,心里大概明白却又说不清。
方案:希望老师多讲讲这新知识,相信很多同学和我一样,懵懵懂懂的。
4、运行截图