Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- int main(int argc, char* argv[]) {
- double sum = 0;
- int fd = open(argv[1], O_RDONLY);
- struct stat buf;
- fstat(fd, &buf);
- double *map = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
- size_t size = buf.st_size / sizeof(double);
- for (size_t i = 0; i < size; i++) {
- sum += map[i];
- }
- printf("%a\n", sum / size);
- munmap(0, buf.st_size);
- close(fd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement