char 배열에 int 값 넣기

2019. 7. 24. 13:46PL/C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define OPSZ 4 // 정수형 사이즈
char buf[1024];
int main(int argc, char **argv)
{
for(int i=0; i<5; i++) {
scanf("%d", (int*)&buf[OPSZ*i]);
}
for(int i=0; i<5; i++) {
printf("%d ", *(int*)&buf[OPSZ*i]);
}
printf("\n");
return 0;
}
view raw chartoint.c hosted with ❤ by GitHub

'PL > C++' 카테고리의 다른 글