Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #define MAX_FILE_SIZE 65535
- int main ()
- {
- int fd = open("~/input.txt",O_RDONLY,0);
- void *bytes;
- void *byteptr;
- int i = 0;
- if (fp == -1)
- {
- printf("File not found!\n");
- exit(EXIT_FAILURE);
- }
- bytes = mmap(NULL,MAX_FILE_SIZE,PROT_READ,MAP_PRIVATE,fd,0);
- while ((char)*byteptr != EOF)
- {
- char *line = malloc(256*sizeof(char));
- char *lineptr = line;
- int line_size = 0;
- while (*lineptr++ = (char) *byteptr++ != '\n' && (char) *byteptr != EOF)
- line_size++;
- *lineptr = '\0';
- printf("Line size: %s\nLine: %s\n",line_size,line);
- i++;
- free(line);
- }
- munmap(bytes, MAX_FILE_SIZE);
- close(fd);
- printf("Total lines: %i\n", i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement