Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- long int filesize (FILE * fp) {
- long int save_pos, size_of_file;
- save_pos = ftell(fp);
- fseek(fp, 0L, SEEK_END);
- size_of_file = ftell(fp);
- fseek(fp, save_pos, SEEK_SET);
- return(size_of_file);
- }
- int main (int argc, char * argv[]) {
- FILE * fin;
- FILE * fout;
- fout = fopen("output.txt", "w");
- if (argv[1] == NULL) {
- fprintf(fout, "Usage: stat filename\n");
- fclose(fout);
- exit(1);
- } else {
- fin = fopen(argv[1], "r");
- if (fin == NULL) {
- fprintf(fout, "Can't open file %s", argv[1]);
- fclose(fout);
- exit(2);
- } else {
- fprintf(fout, "%ld", filesize(fin));
- fclose(fout);
- fclose(fin);
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement