【发布时间】:2015-09-24 09:40:09
【问题描述】:
我正在尝试使用选项卡在一行中打印枚举中的所有内容以分隔每个衬衫尺寸。当我尝试编译我的程序时,它会打印出随机数而不是 S、M、L、XL。
这是我的程序:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
enum SIZE{S,M,L,XL};
int i,j;
int main()
{
enum SIZE s;
int t[4][4]={1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7};
int *p=t;
/********DISPLAY ARRAY******************/
printf("This is our inventory \n");
for(s=S; s<=XL; s=(s+1))
{
printf("%d \t", t[s]);
}
printf("\n");
for( i=0; i<4; i++)
{
for(j=0;j<4; j++)
{
printf("%d\t", *p++);
}
printf("\n");
}
/*****************************************/
printf("\n\n");
system("PAUSE");
return 0;
}
output:
This is our inventory
2686668 2686684 2686700 2686716
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
按任意键继续。 . .
我不明白为什么要打印以下行:
2686668 2686684 2686700 2686716
相对于:
S M L XL
谁能解释造成这种情况的原因?
【问题讨论】:
-
t被声明为二维数组,但您将其打印为一维数组! -
在使用枚举之前可能想研究一下枚举是什么。