Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <fcntl.h>
- #include <stdio.h>
- int main()
- {
- int fd;
- const size_t size = 13;
- char str[size + 1] = {0};
- if ((fd = open("myfile", O_RDONLY)) < 0)
- {
- printf("Can\'t open file\n");
- exit(-1);
- }
- int offset = 0,
- bytes_read;
- for (; (bytes_read = read(fd, str + offset, size - offset)) > 0;)
- {
- offset += bytes_read;
- }
- printf("%s\n", str);
- if (close(fd) < 0)
- {
- printf("Can\'t close file\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement