Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- int main()
- {
- int lines_to_print = 0;
- int i = 0;
- int num_lines = 0;
- char buffer[500];
- int first_file = open("first.txt", O_RDONLY);
- if(first_file < 0)
- {
- perror("Error in opening the first file");
- return 0;
- }
- while (read(first_file, buffer, 1))
- {
- for (i = 0; buffer[i]; i++)
- { if (buffer[i] == '\n')
- {
- num_lines++;
- }
- }
- }
- lines_to_print = num_lines - 10;
- for (i = lines_to_print; i <= num_lines; i++)
- {
- write(STDOUT_FILENO, &buffer[i], 10);
- }
- close(first_file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement