This is probably going to be embarrassing, but here we go! I have the following code (shown below), and it is suppose to take an int and convert it to an char string. (I know about itoa() and snprintf, but I wan't to make it work like this.) Everything seem's to work fine until I try to print it and it displays nothing for the inttochar string. It's probably just something stupid I've overlooked... I get the following result:
CHAR1: 4334321
CHAR2: 1234334
CHAR3:
The code is here:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
int tester = 1234334; //Test value
char temp[10]; //Temporary string array.
char inttochar[10];
int t = 0;
//Reads int to array.
while(tester != 0){
temp[t] = (tester % 10) + '0';
tester /= 10;
t++;
}
temp[t] = '\0';
t = 0;
printf("CHAR1: %s\nCHAR2: ",temp);
//Reverses the string.
for(int j=strlen(temp); j>=0;j--){
inttochar[t] = temp[j];
printf("%c",inttochar[t]);
t++;
}
inttochar[t] = '\0';
t = 0;
printf("\nCHAR3: %s\n",inttochar);
}