Last active
May 18, 2017 21:25
-
-
Save atroche/fe757cc547cace688a65324fa8f99de9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <err.h> | |
#include <unistd.h> | |
#include <inttypes.h> | |
#define BUF_SIZE (1048576 * 10) | |
int main(int argc, char *argv[]) | |
{ | |
static char char_buf[BUF_SIZE]; | |
static ssize_t buf_size = BUF_SIZE; | |
void *buf = char_buf; | |
char *p; | |
ssize_t len; | |
uint64_t linect; | |
int fd = open("ten.json", O_RDONLY); | |
if (fd < 0) { | |
warn("bad open"); | |
return 1; | |
} | |
/* | |
while((len = read(fd, buf, buf_size))) { | |
for(p=buf;len--;p++){ | |
if(*p == '\n'){ | |
linect++; | |
} | |
} | |
} | |
*/ | |
// faster! | |
while((len = read(fd, buf, buf_size))) { | |
for(p=buf;len>0;p+=2){ | |
if(*p == '\n'){ | |
counta++; | |
} | |
if(*(p+1) == '\n'){ | |
countb++; | |
} | |
len -=2; | |
} | |
} | |
printf("%" PRIu64 "\n", linect); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure how this compiles and does anything. Line 37 and line 40 reference undeclared variables
counta
andcountb
, neither of which are listed as computinglinect
.