이것은 아마 당혹 스러울 것입니다,하지만 여기에 우리가 간다! 다음 코드 (아래 참조)가 있으며 int를 사용하여 char 문자열로 변환한다고 가정합니다. (나는 itoa()와 snprintf에 대해 알고 있지만, 이렇게 작동하게하지는 않을 것입니다.) 인쇄를 시도 할 때까지 모든 것이 잘 작동하는 것처럼 보입니다. inttochar 문자열에는 아무 것도 표시되지 않습니다. 그것은 아마 내가 간과 한 어리석은 단지 뭔가 ... 나는 다음과 같은 결과를 얻을 :인쇄 문자열이 아닙니다. char 배열
CHAR1: 4334321
CHAR2: 1234334
CHAR3:
코드는 여기에 있습니다 :
#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);
}
'for (int j = strlen (temp); j> = 0; j -) {'이것은 하나씩 꺼져 있습니다. – wildplasser