- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
|
大家好,我做了有一个月,问了好多人,还是Ouput wrong . short form 的
Attendance.txt
1 1 0
1 0 1
1 1 1
0 1 1
0 0 1
0 1 0
0 0 1
#define MAX_WEEKS 7
#define MAX_STUDENTS 10
int studCount,weekCount;
int Attendance[MAX_WEEKS][MAX_STUDENTS];
variable 有。。。。可以assignvalue
void Read_Attendance_Into_Array()
{
FILE*fp;
int total_present=0;
fp=fopen("Attendance.txt","r");
if (fp==NULL)
{
printf("Error\n");
exit(-1);
}
else
{
printf("Reading Attendance details for Week #\n");
printf("0...1...2...3...4...5...6...\n\n");
printf("Attendance for each week\n");
printf("------------------------\n");
while (fscanf(fp,"%d",student)!=EOF)
{
for (weekCount=0;weekCount<MAX_WEEKS;weekCount++)//MAX_WEEKS 7
{
printf("Week NO %d :",weekCount+1);
for (studCount=0;studCount<MAX_STUDENTS;studCount++)//MAX_STUDENTS 10
{
fscanf(fp,"%d",Attendance[weekCount][studCount]);
if (Attendance[weekCount][studCount]==1)
{
total_present=total_present+1;
}
}
printf("%d students present\n",total_present);
total_present=0;
}
printf("\n");
}
}
fclose(fp);
}
我的output
week 1 7
week 2 4
week 3 0
week 4 0
week 5 0
week 6 0
week 7 0
看下。。。
pang1989 发表于 2010-11-25 11:45 PM
修改成以下即可读取最後一個字节
while( !feof( fp ) ) |
|