请高手指点此程序错在哪?
数据结构基础里的一个习题答案,但总有一个错误。程序如下:
#include <stdio.h>
#include <string.h>
typedef struct {double length, width;} rectStuff;
typedef struct {double base, height;} triStuff;
typedef struct {
char name[10];
enum tagField {rectangle, triangle, circle} shapeType;
union {
rectStuff rect;
triStuff tri;
double radius;
} stats;
}shape;
void printShape(shape);
int main()
{
shape s1, s2, s3;
strcpy(s1.name, "rectangle");
s1.shapeType = rectangle;//error C2065: 'rectangle' : undeclared identifier 提示出错在这里
s1.stats.rect.length = 10;
s1.stats.rect.width = 20;
strcpy(s2.name, "triangle");
s2.shapeType = triangle;
s2.stats.tri.base = 102;
s2.stats.tri.height = 450;
strcpy(s3.name ,"circle");
s3.stats.radius = 2.5;
/* printf("%f\n",s3.stats.radius);*/
printShape(s1);
printShape(s2);
printShape(s3);
}
void printShape(shape s)
{/*print out the information on a shape */
printf("Name: %s\n", s.name);
switch(s.shapeType){
case rectangle:
printf("\tLength:%f\n", s.stats.rect.length);
printf("\tWidth:%f\n\n", s.stats.rect.width);
break;
case triangle:
printf("\tBase:%f\n", s.stats.tri.base);
printf("\tHeight:%f\n\n", s.stats.tri.height);
break;
case circle:
printf("Radius:%f\n",s.stats.radius);
break;
}
}
[ 本帖最后由 seekdream 于 2011-5-28 16:13 编辑 ]