Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. FILE *f = fopen("a.txt", "r");
  2. fseek(f, 0, 2);
  3. int size = ftell(f);
  4. fseek(f, 0, 0);
  5.  
  6. printf("%d\n", size);
  7. char *res = malloc((size+1)*sizeof(char));
  8. fread(res, sizeof(char), size, f);
  9. res[size-2] = '\0';
  10. printf("%s", res);
  11.  
  12. char buff[100];
  13. fseek(f, 0, 0);
  14. while(!feof(f))
  15. {
  16. if (fgets(buff, 100, f) > 0)
  17. printf("%s", buff);
  18. }
  19. fclose(f);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement