Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <inttypes.h>
  8.  
  9.  
  10. #define ARRAY_SIZE 10
  11.  
  12.  
  13. int main() {
  14. srand(time(NULL));
  15. int file = open(
  16. "file",
  17. O_RDWR | O_CREAT | O_TRUNC,
  18. S_IRUSR | S_IWUSR
  19. );
  20. double array[ARRAY_SIZE];
  21. for (int i = 0; i < ARRAY_SIZE; ++i) {
  22. array[i] = i;
  23. }
  24. for (int i = 0; i < ARRAY_SIZE; ++i) {
  25. printf("%d: %lf\n", i, array[i]);
  26. }
  27. int length = ARRAY_SIZE * sizeof(double);
  28. char* data = (char*)array;
  29. while (length > 0) {
  30. ssize_t wrote = write(file, data, length);
  31. length -= wrote;
  32. data += wrote;
  33. }
  34. close(file);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement