Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------
- // NAME: Dimitur Stoilov
- // CLASS: XIa
- // NUMBER: 8
- // PROBLEM: #1
- // FILE NAME: files.c
- // FILE PURPOSE:
- // Prints the first 10 lines of a file
- // ...
- //-----------------------------------------------------------------------
- #include<stdio.h>
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<unistd.h>
- int main(){
- char buff;
- int count = 0;
- int w_result;
- int a=0;
- int fd = open("a.txt", O_APPEND);
- if(fd == -1){
- write(1, "error\n", 6);
- }
- int result = 1;
- while(result > 0){
- if(buff=='\n'){
- count++;
- if(count==10){
- break;
- }
- }
- result = read(fd, &buff, 1);
- int written = 0;
- while(written < result){
- w_result = write(STDOUT_FILENO, &buff, result - written);
- if(w_result == -1){
- write(1, "error\n", 6);
- return -1;
- }
- written += w_result;
- }
- }
- if(result == -1){
- write(1, "error\n", 6);
- }
- if(close(fd) == -1){
- write(1, "error\n", 6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement