您的位置:首页 > 编程语言 > C语言/C++

C语言成长学习题(十七)

2015-12-09 12:21 316 查看
81.调用函数,完成单向动态链表的建立,输出各结点的值.

#include <stdio.h>
#include <stdlib.h>

void main (void)
{
int a, max = 0;
FILE *fp;

fp = fopen("d:\\cwz\\b.txt", "r");
if (fp == NULL)
{
printf("Can't open file!\n");
exit(0);
}
while (feof(fp) == 0)
{
fscanf(fp, "%d", &a);
printf("%4d", a);
if (max < a)
max = a;
}
printf("\n");
printf("max = %d\n", max);
fclose(fp);
}


View Code
结果:

60 70 80 90 100 80 60

max = 100

  函数feof用来判断文件是否结束,当数据读取到文件尾部时,feof(fp)的值为1,否则feof(fp)的值为0.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: