char 배열에 int 값 넣기
2019. 7. 24. 13:46ㆍPL/C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
'PL > C++' 카테고리의 다른 글
strstr (0) | 2019.07.27 |
---|---|
fgets와 fputs (0) | 2019.07.26 |
scanf에서 '\n'의 의미 (0) | 2019.07.19 |
swap 함수 define으로 구현하기 (0) | 2019.07.19 |
malloc, calloc으로 2차원 배열 임의의 크기로 다루기 (0) | 2019.07.17 |