gpt4 book ai didi

c - 无法找到导致此错误的原因

转载 作者:行者123 更新时间:2023-11-30 20:12:29 25 4
gpt4 key购买 nike

我正在尝试创建一个程序来输出 16 个数字的二进制代码。这是我到目前为止所拥有的:

#include <stdio.h>
#include <stdlib.h>
int i;
int count;
int mask;

int i = 0xF5A2;
int mask = 0x8000;
int main()
{
printf("Hex Value= %x Binary= \n", i);
{
for (count=0; count<15; count++1)
{
if (i&mask)
printf("1\n");
else
printf("0\n");
}
(mask = mask>>1);
}
return 0;
}

错误:

|16|error: expected ')' before numeric constant|

如果我还有其他错误,请告诉我,提前谢谢!

最佳答案

错误指的是这个表达式:

count++1

这没有任何意义。

我假设你想要:

count++ 

制作线路

for (count=0; count<15; count++)
<小时/>

您的代码中还有其他奇怪之处,例如:

int i;              // Declare an integer named "i"
int mask; // Declare an integer named "mask"

int i = 0xF5A2; // Declare another integer also named "i". Did you forget about the first one???
int mask = 0x8000; // Did you forget you already declared an integer named "mask"?
<小时/>
printf("Hex Value= %x Binary= \n", i);
{
[...]
} // Why did you put a bracket-scope under a PRINTF call?
// Scopes typically follow loops and if-statements!
<小时/>
 (mask = mask>>1);  // Why put parens around a plain-old expression??

<小时/>修复代码中的奇怪问题后,它应该如下所示:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i = 0xF5A2;
int mask = 0x8000;

printf("Hex Value= %x Binary= \n", i);
for (int count=0; count<15; ++count, mask>>=1)
{
printf("%d\n", (i&mask)? 1 : 0);
}
return 0;
}

关于c - 无法找到导致此错误的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com