Created
July 16, 2019 12:15
-
-
Save andrewthad/6ebe64d1e85e77e2fafc5abba1e99230 to your computer and use it in GitHub Desktop.
Read or write 64-bit unsigned words from or to file
This file contains hidden or 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 <stdint.h> | |
#include <unistd.h> | |
#include <inttypes.h> | |
int main () { | |
FILE *file = NULL; | |
uint64_t buffer[1]; // array of bytes, not pointers-to-bytes | |
size_t bytesRead = 0; | |
file = fopen("numbers.bin", "rb"); | |
if (file != NULL) { | |
// for (uint64_t x = 0; x < 1024 * 1024; x++) { | |
// ((uint64_t*)buffer)[0] = x; | |
// fwrite(buffer,1,sizeof(buffer),file); | |
// } | |
// read up to sizeof(buffer) bytes | |
while ((bytesRead = fread(buffer, 1, 8, file)) > 0) | |
{ | |
// process bytesRead worth of data in buffer | |
printf("Another chunk %" PRIu64 "\n", buffer[0]); | |
usleep(10000); | |
} | |
} else { | |
printf("no file\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment