typedef struct &struct 区别 1.typedef struct card { char suit[10]; char face[10]; } CARD; 相当于CARD是card的别名 int main() { CARD c[100];==card c[100]; }
#include#include #include typedef struct card { char suit[10]; char face[10]; } CARD; int main() { CARD c[60]; char *Suit[]={"Spades","Hearts","Clubs","Diamonds"}; 定义字符指针组 char *Face[]={"A","2","3","4","5","6","7","8","9","10","Jack","Queen","King"}; int sum=1; for(int i=0;i<=3;i++) for(int j=0;j<=12;j++,sum++) { strcpy(c[sum].suit,Suit[i]); 字符串的赋值; strcpy(c[sum].face,Face[j]); } for(int i=1;i<=52;i++) printf("%9s%9sn",c[i].suit,c[i].face); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)