daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Dec 11th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. long int filesize (FILE * fp) {
  5.     long int save_pos, size_of_file;
  6.    
  7.     save_pos = ftell(fp);
  8.     fseek(fp, 0L, SEEK_END);
  9.     size_of_file = ftell(fp);
  10.     fseek(fp, save_pos, SEEK_SET);
  11.    
  12.     return(size_of_file);
  13. }
  14.  
  15. int main (int argc, char * argv[]) {
  16.     FILE * fin;
  17.     FILE * fout;
  18.    
  19.     fout = fopen("output.txt", "w");
  20.    
  21.     if (argv[1] == NULL) {
  22.         fprintf(fout, "Usage: stat filename\n");
  23.         fclose(fout);
  24.         exit(1);
  25.     } else {
  26.         fin = fopen(argv[1], "r");
  27.        
  28.         if (fin == NULL) {
  29.             fprintf(fout, "Can't open file %s", argv[1]);
  30.             fclose(fout);
  31.             exit(2);
  32.         } else {
  33.             fprintf(fout, "%ld", filesize(fin));
  34.             fclose(fout);
  35.             fclose(fin);
  36.             exit(0);
  37.         }
  38.     }
  39.    
  40.     return 0;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top