|
5鱼币
#include "stdafx.h"
#include <stdio.h>
/*位字段*/
#define YES 1
#define NO 0
/*边框线样式*/
#define SOLOID 0
#define DOTTED 1
#define DASHED 2
/*三原色*/
#define BLUE 4
#define GREEN 2
#define RED 1
#define BLACK 0
#define YELLOW (RED | GREEN)
#define MAGENTA (RED | BLUE)
#define CYAN (GREEN | BLUE)
#define WHITE (RED | GREEN| BLUE)
/*位运算使用的常量*/
#define OPAQUE 1
#define FILL_BLUE 1<<3
#define FILL_GREEN 1<<2
#define FILL_RED 1<<1
#define FILL_MASK 0xE
#define BORDER 1<<8
#define BORDER_BLUE 1<<11
#define BORDER_GREEN 0x400
#define BORDER_RED 0x200
#define BORDER_MASK 0xE00
#define B_SOLID 0
#define B_DOTTED 0x1000
#define B_DASHED 0x2000
#define STYLE_MASK 0x3000
const char *color[8]={"black","red","yellow","green","blue","maenta","cyan","white"};
struct box_porops
{
unsigned int opeaque :1;
unsigned int fill_color :3;
unsigned int :4;
unsigned int show_border :1;
unsigned int border_color :3;
unsigned int border_style :2;
unsigned int :2;
};
union Views
{
struct box_porops st_view;
unsigned int ui_view;
};
void show_setting(const struct box_porops *pb);
void show_setting1(unsigned short);
char *itobs(int n,char *ps);
int _tmain(int argc, _TCHAR* argv[])
{
union Views box={{YES,YELLOW,YES,GREEN,DASHED}};
// box.st_view.fill_color=3;
char bin_str[8*sizeof(unsigned int)+1];
printf("Original box setting:\n");
show_setting(&box.st_view);
printf("\nBox setting using usingned int view:\n");
//show_setting1(box);
return 0;
}
void show_setting(const struct box_porops *pb)
{
printf("Box is %s\n",pb->opeaque==YES? "opeaue":"transparent");
printf("The fill color is %s \n",color[pb->fill_color]);
}
这段代码还没完成 但是我对这个 printf("The fill color is %s \n",color[pb->fill_color]);
不理解, 这个是指 指向fill_color这个结构的值 但是他输出的green但是我赋予给他的是yellow,请大神赐教下 请告诉我 为什么指向green 我想在初始化得时候就赋予给whiter又该如何操作
|
最佳答案
查看完整内容
晕死,这么死犟,你的数组写错了么。
原来的原因:
访问数组【3】(pb->fill_color 的值是3),就是数组的第四个元数,是不是green啊?????
const char *color[8]={"black","red","yellow","green","blue","maenta","cyan","white"};
const char *color[8]={位置0,位置1,位置2,位置3,位置4,位置5,位置6,位置7};
|