DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

File Length In Bytes

02.09.2006
| 190 views |
  • submit to reddit
        
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
  struct stat file_status;

  /* parsing the command line */
  if (argc!=2) {
    fprintf(stderr, "Usage: filelen file_name\n");
    exit(1);
  }
  else {
    if (stat(argv[1], &file_status)) {
      fprintf(stderr, "Error occured!\n");
      exit(2);
    }
    else
      printf("%d\n", file_status.st_size);
  }

  return(0);
}
    
    Tags:
  • C