我有一个运行时错误,它从数组写入的数据多于其打印ID,AverageMarks和Status:
宣言及其功能
char StudentStatus[10][7];
for(x=0;x<10;x++)
{
fprintf(OutputFile,"%d\t\t%d\t\t\t%s\n",StudentID[x],StudentAvg[x],StudentStatus[x]);
}
Run Code Online (Sandbox Code Playgroud)
但是当它打印出来时
100 77 DismissActive
101 85 Active
102 88 Active
103 86 Active
104 85 Active
105 84 Active
106 84 Active
107 82 Active
108 92 Active
109 75 Dismiss
数组的填充方式:
for(x=0;x<NumOfStudent;x++)
{
if(StudentAvg[x]>80)
{
strcpy(StudentStatus[x],"Active");
printf(". ");
}
else
{
strcpy(StudentStatus[x],"Dismiss");
printf(". ");
}
}
Run Code Online (Sandbox Code Playgroud)
其他声明工作正常,但第一个声明真的很麻烦我.我错误编码的任何建议?
要允许终止null,请将数组声明更改为:
char StudentStatus[10][8];
Run Code Online (Sandbox Code Playgroud)
C字符串以空值终止,因此字符串"Dismiss"至少需要8个字节的存储空间.
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |