如何在c上打印内部供应的结构?

如何在c上打印内部供应的结构?,c,struct,printf,C,Struct,Printf,在代码中以二进制数字字符串的形式打印,但我不知道如何才能做到这一点。你能帮我吗?按如下方式更改代码中的行: struct game games[n] 然后在返回0之前添加以下块的main(): 你可以决定你是喜欢选项1还是选项2。你的问题有点不清楚,但是如果你只想把游戏数组的原始内容打印成十六进制值,你可以这样做:char*ptr=(char*)games;对于(inti=0;i

在代码中以二进制数字字符串的形式打印,但我不知道如何才能做到这一点。你能帮我吗?

按如下方式更改代码中的行:

struct game games[n]
然后在
返回0之前添加以下块
main()


你可以决定你是喜欢选项1还是选项2。

你的问题有点不清楚,但是如果你只想把
游戏
数组的原始内容打印成十六进制值,你可以这样做:
char*ptr=(char*)games;对于(inti=0;i顺便说一句,由于C中的布尔值仅为0和1,因此不需要使用
if
语句,您可以直接赋值,例如
games[i]SGeorgiades,这个结构只包含0和1,你的建议是正确的。谢谢你的帮助
struct game games[n]
int n,a,b,c,d,i;
char *ptr = (char*)games;
for (i = 0; i < sizeof(games); ++i) printf(" %02X",ptr[i]);   /* Option 1 */
printf("\n");

for (i = 0; i < sizeof(games); i+=4) 
printf("%1X%1X%1X%1X",ptr[i],ptr[i+1],ptr[i+2],ptr[i+3]);     /* Option 2 */
How much games do you want?:3
Here is the information about all games we have:

 is the game a computer one: 1
is the game a tabletop one: 0
is the game for children: 0
is the game a collective one: 1

is the game a computer one: 1
is the game a tabletop one: 0
is the game for children: 1
is the game a collective one: 1

is the game a computer one: 0
is the game a tabletop one: 1
is the game for children: 0
is the game a collective one: 1

 01 00 00 01 01 00 01 01 00 01 00 01           /* Option 1 */
 1001 1011 0101                                /* Option 2 */