title: c comparing file sizes using fstat issue
body: <p>My code comparing 2 file sizes seems to behave as if <code>keyfile</code> > <code>sourcefile</code>. Is there something missing from the code below and what can I change? The two files I'm using for testing are 3kb keyfile and 14kb sourcefile, which should activate the last <code>if</code> statement provided below.</p>
  
  <pre><code>/* Get size of sourcefile. */
  if((sourcefile = fopen(argv[1], "rb"))== NULL)
  {
  printf("Can't open source file.\n");
  printf("Please enter a valid filename.\n");
  printf("USAGE: OTP &lt;source file&gt; &lt;output file&gt; &lt;keyfile&gt;\n");
  return (1);
  }
  
  fflush(sourcefile);
  fstat(fileno(sourcefile), &amp;statbuf);
  fclose(sourcefile);
  
  /* Get size of keyfile. */
  if((keyfile = fopen(argv[3], "rb"))== NULL)
  {
  printf("Can't open keyfile.\n");
  printf("Please enter a valid filename.\n"); 
  printf("USAGE: OTP &lt;source file&gt; &lt;output file&gt; &lt;keyfile&gt;\n");
  return(1);
  
  fflush(keyfile);
  fstat(fileno(keyfile), &amp;keybuf);
  fclose(keyfile);
  }
  
  /* Open necessary files. */
  keyfile=fopen(argv[3], "rb");
  sourcefile=fopen(argv[1], "rb");
  destfile=fopen(argv[2], "wb");
  
  /* Check if keyfile is the same size as, or bigger than the sourcefile */
  if((keybuf.st_size) &lt; (statbuf.st_size))
  {
  printf("Source file is larger than keyfile.\n");
  printf("This significantly reduces cryptographic strength.\n");
  printf("Do you wish to continue? (Y/N)\n");
  scanf("%c", &amp;ans);
  if(ans == 'n' || ans == 'N')
      {
      return (1);
      }
  if(ans == 'y' || ans == 'Y')
      {
      printf("Proceeding with Encryption/Decryption.\n");
      }
  }   
  </code></pre>