Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<fcntl.h>
- int main()
- {
- int fd;
- fd = open("test.txt", O_RDONLY); // 파일을 읽기전용으로 오픈하기
- char * array = (char * )malloc(1024);
- memset(array, 0, 1024); // array를 0으로 초기화
- read(fd, array, 1024);
- // 파일디스크립터를 통해 접근하여 파일 내용을 array에 파일의 크기만큼 저장
- printf("%s\n", array); // 파일의 내용출력
- close(fd);
- free(array);
- return 0;
- }
Add Comment
Please, Sign In to add comment