大家好,我做了有一个月,问了好多人,还是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
回复 Super-Tomato
#define MAX_WEEKS 7
#define MAX_STUDENTS 3
int Attendance[MAX_WEEKS][MAX_STUDENTS]={0};
int student;
int total_present=0;
student=Attendance[0][0];
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;
}
output
2
2
2
2
1
1
1
少一个。。。
text file same ...
pang1989 发表于 2010-11-26 03:29 AM
番茄,你的 editor 很美。是什么 editor 来的?
~Zero 发表于 2010-11-26 01:37 PM
回复 Super-Tomato
还真的是 GEDIT哦,我乱猜的
Software center 应该有更好地 editor 吧:R ...
宅男-兜着走 发表于 2010-11-27 03:09 AM
欢迎光临 JBTALKS.CC (https://jbtalks.my/) | Powered by Discuz! X2.5 |