diadia <> wrote:
> #include <sys/types.h>
> #include <sys/stat.h>
These are non-standard headers.
> #include "ctype.h"
> #include <stdio.h>
> int estimateLen(struct stat buf, FILE *fp)
> {
> size_t _size = buf.st_size / 4;
Identifiers starting with an underscore are reserved for the implemen-
tation and shouldn't (or may not) be used by normal programs. What
happens if you rename it to e.g. 'size'?
> printf("%d %d\n",buf.st_size,_size); //result is wrong,_size is zero?
'size_t' is (normally not an int) but some unsigned integer. Better
cast it to unsigned long and then use "%lu" as the format specifier
(unless you have a C99 compliant compiler and can use "%zu").
> printf("%d %d\n",_size,buf.st_size); //result is correct
> }
Where's the return statement? You promised to return an int.
> int main(int argc,char*argv[])
> {
> FILE *fp;
> struct stat s;
> if (stat(argv[argc-1],&s))
> printf("stat error\n");
Shouldn't you bail out in that situation instead of calling your
function with a structure that's probably uninitialized?
> estimateLen(s,fp);
> }
And, again, you need to return something here.
> I don't know _size show zero in the first printf function
> Is it a bug?
On my system exists a stat() function that perhaps has the same
purpose as the one on your system (assuming you're using some
kind of UNIX - there is no stat() function in standard C and on
my system the 'st_size' member of the stat structure is of type
off_t, which may or may not make a difference) and I can't repro-
duce the error you seem to get.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://www.toerring.de