2
0

fwrite.c 478 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. FILE *f = fopen("stdio/fwrite.out", "w");
  7. ERROR_IF(fopen, f, == NULL);
  8. const char ptr[] = "Hello World!";
  9. if (fwrite(ptr, 0, 17, f)) {
  10. exit(EXIT_FAILURE);
  11. }
  12. if (fwrite(ptr, 7, 0, f)) {
  13. exit(EXIT_FAILURE);
  14. }
  15. if (fwrite(ptr, 0, 0, f)) {
  16. exit(EXIT_FAILURE);
  17. }
  18. fwrite(ptr, sizeof(ptr), 1, f);
  19. fclose(f);
  20. }