0

我正在用 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
          }

}

这可能只是因为我在编码数小时后感到疲倦。我很确定这是简单而基本的东西,但我似乎找不到它。

4

1 回答 1

2

您的声明:

sprintf(stringbinary, "%d", binary);//conversion of the array to string

表示您误解了如何将整数数组转换为字符串。

上面的行将获取 的地址binary,将其转换为整数,并将地址打印为整数。

如果要打印binarystdout数字之间没有任何空格,可以使用:

for (i = 0; i < 8; ++i )
{
   printf("%d", binary[i]);
}
print("\n");

确保添加一行

int i;

for在使用该循环之前在函数的开头。

于 2014-05-28T06:12:00.063 回答