delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/01/06/21:29:55

From: Dmitry Rutsky <deemus AT rambler DOT ru>
To: djgpp AT delorie DOT com
Subject: File reading problem
Date: Tue, 7 Jan 2003 04:13:11 +0300
User-Agent: KMail/1.4.3
MIME-Version: 1.0
Message-Id: <200301070413.12292.deemus@rambler.ru>
Reply-To: djgpp AT delorie DOT com

--------------Boundary-00=_ZPKBXSDEXFUEFHPS0N06
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

=09Hello.

Why doesn't the included program work correctly?  It is supposed to deter=
mine=20
file sizes by dumb method, and does it under Linux. But when I tried it w=
ith=20
the latest DJGPP, both in DOSEmu and Windows 2000, it gave wrong numbers =
for=20
almost any files.  I've discovered this problem when I tried to test the=20
abilities of DJGPP by entertaining with my old school project, a Huffman =
file=20
archiver.  It worked fine under Linux, but cannot work at all under DJGPP=
=2E

=09--- Dmitry Rutsky

--------------Boundary-00=_ZPKBXSDEXFUEFHPS0N06
Content-Type: text/x-csrc;
  charset="us-ascii";
  name="size.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="size.c"

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
   if (argc < 2)
      printf ("USAGE: %s <filename>\n", argv [0]);
   else
   {
      FILE *f;

      f = fopen (argv [1], "r");
      if (!f)
         perror ("fopen");
      else
      {
	 int size = 0;

	 while (fgetc (f) != EOF)
	    size ++;

	 printf ("%d\n", size);

	 fclose (f);
      }
   }
}


--------------Boundary-00=_ZPKBXSDEXFUEFHPS0N06--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019