2
0

fread.c 432 B

1234567891011121314151617181920212223
  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. FILE *fp = fopen("stdio/fread.in", "rb");
  7. ERROR_IF(fopen, fp, == NULL);
  8. char buf[33] = { 0 };
  9. for (int i = 1; i <= 32; ++i) {
  10. if (fread(buf, 1, i, fp) < 0) {
  11. perror("fread");
  12. exit(EXIT_FAILURE);
  13. }
  14. buf[i] = 0;
  15. printf("%s\n", buf);
  16. }
  17. fclose(fp);
  18. }