到目前爲止,我已經寫了幾行將整數轉換爲數組。將整數轉換爲數組
#include <stdio.h>
int main(int argc, char *argv[]){
int num = 9214;
int count = 3;
char numarray[3];
int temp;
while(num > 0){
temp = num % 10;
numarray[count] = temp;
num /= 10;
count--;
}
printf("Array: ");
for(count = 0; count <= 3; count++)
printf("%d", numarray[count]);
printf("\n\n");
}
輸出應該是9214.然而,返回爲9219 如果我改變變量NUM 5183,它將返回爲5185 它改變了數組的最後一個號到num的第一個數字變量。
有沒有人有任何想法,我已經搞砸了?
我覺得有點愚蠢,因爲我試圖增加幾乎所有東西的大小,除此之外。我可以問爲什麼它將最後一位數字變爲變量中的第一位數字? – Jack
嘗試更多示例,然後才能斷定它將最後一位數字變爲變量中的第一位數字。你正在走出界限。 – innoSPG