So far I have written a few lines to convert an integer to an array.
#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");
}
The output should be 9214. However, it returns as 9219. If I change the variable num 5183, it would return as 5185. It changes the last number of the array to the first number of the num variable.
Does anyone have any idea where I've messed up?