Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <inttypes.h>
- #define ARRAY_SIZE 10
- int main() {
- srand(time(NULL));
- int file = open(
- "file",
- O_RDWR | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR
- );
- double array[ARRAY_SIZE];
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- array[i] = i;
- }
- for (int i = 0; i < ARRAY_SIZE; ++i) {
- printf("%d: %lf\n", i, array[i]);
- }
- int length = ARRAY_SIZE * sizeof(double);
- char* data = (char*)array;
- while (length > 0) {
- ssize_t wrote = write(file, data, length);
- length -= wrote;
- data += wrote;
- }
- close(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement