我在C中使用uVision 4进行编码以进行ARM分配。 我似乎无法解决这个问题,但每次我继续得到字符串" 536876144"。
int main(void) {
int binary[8] = {0,0,0,0,0,0,0,0};//I want this array as integers (for binary terms), therefore i can toggle each number as 1 or 0, corresponding to the input.
char stringbinary[9]; //string for recording the value of the converted integer array
sprintf(stringbinary, "%d", binary);//conversion of the array to string
printf("%s\r\n",stringbinary);//printing the value
.............
.............
if(input=1){
binary[0]=1 - binary[0]; // I have the each value of the array to toggle with activation
}
}
可能只是因为我经过数小时的编码后感到疲惫。我很确定这是一件简单而基本的事情,但我似乎无法找到它。
答案 0 :(得分:2)
您的陈述:
sprintf(stringbinary, "%d", binary);//conversion of the array to string
表示您误解了如何将整数数组转换为字符串。
上面的行将取binary
的地址,将其转换为整数,并将地址打印为整数。
如果您想将binary
打印到stdout
,且号码之间没有任何空格,您可以使用:
for (i = 0; i < 8; ++i )
{
printf("%d", binary[i]);
}
print("\n");
确保添加一行
int i;
在使用for
循环之前的函数开头。