enter image description here我目前正在完成程序,遇到无法解决的问题。我正在使用一个char数组从输入文件中打印团队名称。名称最初是从文件中正确保存的,但是我嵌套的for循环提取统计信息的int array [] []却以某种方式破坏了char数组中的这些名称。 in数组的输出正常进行,但是我无法弄清楚嵌套的for循环后会发生什么变化,这会改变我的char数组的输出。
有什么想法吗?非常感谢您的提前帮助。
-克里斯
我已经测试了输出,以确保我从文件中正确接收了数据。
for (i = 0; i < LEAGUE_SIZE; i++)
{
fscanf(ifp, "%12s", &teams[i]);
}
printf ("...TEAMS FILLED FROM FILE...\n");
printf ("%s\n", teams[0]);
printf ("%s\n", teams[1]);
printf ("%s\n", teams[2]);
printf ("%s\n", teams[3]);
printf ("%s\n", teams[4]);
printf ("%s\n", teams[5]);
for (i = 0; i < LEAGUE_SIZE; i++)
{
for (j = 0; j < STATS; ++j)
{
fscanf(ifp, "%d&c", &num, &dump);
tStats[i][j] = num;
}
}
printf ("...STATS FILLED FROM SAME FILE...\n");
printf ("%s\n", teams[0]);
printf ("%s\n", teams[1]);
printf ("%s\n", teams[2]);
printf ("%s\n", teams[3]);
printf ("%s\n", teams[4]);
printf ("%s\n", teams[5]);
printf ("\n...PRINTING LEAGUE STANDINGS...\n");
printf (" %5s %5s %5s\n", "W", "L", "T");
for (i = 0; i < LEAGUE_SIZE; ++i)
{
printf ("%s\n", teams[0]);
for (j = 0; j < STATS; ++j)
{
printf (" %3d", tStats[i][j]);
}
printf ("\n");
}