C++프로그래밍

2013.05.08_read_write()

성엽이 2013. 5. 14. 09:57

#include < stdio.h >


int main()

{

char t[] = "HIHIHIHIHI\n"; // 11byte

char ch[10]; // 10byte

int iRet=0;


write(1, t, sizeof(t)-1); // stdout(화면출력) t에 t 사이즈만큼 출력

write(1,"안녕하세요\n", sizeof("하이")); // 1번-화면 11byte 로 쓴다.

putchar('\n');  // 4byte(=하이)만큼 적힘.

iRet = read(0, &ch, sizeof(ch)); // NULL 값은 안넣어줌

ch[iRet-1] = 0; // 적는 글자 수만큼 NULL값없이 iRet에 들어감 


putchar('\n'); 

printf("[%s]\n", ch);  

write(1, &ch, iRet-1); // ch에 적힌 글자만큼 출력됨


return 0;

}