View difference between Paste ID: 6taGcfBi and GXnrEwfR
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <stdlib.h>
3-
#include <string.h>
3+
#include <fcntl.h>
4
#include <sys/mman.h>
5
6
#define MAX_FILE_SIZE 65535
7-
	FILE *fp;
7+
8-
	char *line = NULL;
8+
9-
	char n[100][100];
9+
10
	int fd = open("~/input.txt",O_RDONLY,0);
11
	void *bytes;
12-
	fp = fopen("INPUT.txt", "r");
12+
    void *byteptr;
13
	int i = 0;
14-
	if (fp == NULL)
14+
15
	if (fp == -1)
16
	{
17
		printf("File not found!\n");
18
		exit(EXIT_FAILURE);
19
	}
20-
	while (((line = fgets(n[i], 100, fp)) != NULL) && (i < 100))
20+
21
    bytes = mmap(NULL,MAX_FILE_SIZE,PROT_READ,MAP_PRIVATE,fd,0);
22-
		printf("Line length: %i\n", strlen(n[i]));
22+
23-
		printf("Line: %s", n[i++]);
23+
    while ((char)*byteptr != EOF)
24
    {
25-
	
25+
        char *line = malloc(256*sizeof(char));
26-
	fclose(fp);
26+
        char *lineptr = line;
27-
	printf("Total lines: %i", i);
27+
        int line_size = 0;
28
        while (*lineptr++ = (char) *byteptr++ != '\n' && (char) *byteptr != EOF)
29
            line_size++;
30
        *lineptr = '\0';
31
        printf("Line size: %s\nLine: %s\n",line_size,line);
32
        i++;
33
    }
34
35
    munmap(bytes, MAX_FILE_SIZE);  
36
	close(fd);
37
	printf("Total lines: %i\n", i);
38
}