Re: printf and stat problem



diadia wrote:
#include <sys/types.h>
#include <sys/stat.h>

You have been told that these headers are non-standard. Remove anything that interfers with compiling with a standard C compiler on a platform other than yours. If this stuff were relevant, you would be in the wrong place.
#include <ctype.h>
#include <stdio.h>


int estimateLen(struct stat buf, FILE *fp) {

        int size = buf.st_size / 4;
        printf("%d %d\n",buf.st_size,size);
        printf("%d %d\n",size,buf.st_size);
}

int main(int argc,char*argv[])
{
    FILE *fp;
    struct stat s;


if (stat(argv[argc-1],&s)) printf("stat error\n");

    estimateLen(s,fp);
    return 0;

}

i change my code like this

sorry .... although it's not stand,thanks for replying

You really should pay attention next time. I don't know why I bothered carefully explaing your problem to you if you were going to ignore me. If buf.st_size is not an int, then you are calling printf incorrectly. Watch:


#include <ctype.h>
#include <stdio.h>

struct stat
{
    size_t st_size;
};

void estimateLen(struct stat buf)
{

    int size = buf.st_size / 4;
    printf("%d %d\n", (int) buf.st_size, size); /* NOTE */
    printf("%d %d\n", size, (int) buf.st_size);
}

int main(void)
{
    struct stat s = {.st_size = 7949 };
    estimateLen(s);
    return 0;

}
.



Relevant Pages

  • Re: converting 1944 to 1,9,4,4
    ... >int main ... It was compiling for /me/ due to the headers included by ... tostring.h in the platform I happen to be using, ...
    (comp.lang.cpp)
  • Re: Explain this
    ... At least in C and C++, the fact that we're assigning a char to x ... and C++ in a different way: in C, a character literal has type int, ... compiling it as C++ would assign to the global. ... but a language that was considerably different ...
    (comp.lang.cpp)
  • Re: problem with cast and unions
    ... my aim is to make a library compiling with suncc. ... The part where there is that problem is about conversion from a C float ... to a Small "cell" (actually an int). ... contain a valid representation of an 'int'. ...
    (comp.lang.c)
  • Re: Linking Problem
    ... the actual performance cost for CPU-bound code is ... With MF COBOL you have the option of compiling to INT, ...
    (comp.lang.cobol)
  • Re: GCC difference in size of long int on Suse SLES9 / Suse Professional 10.0
    ... I have a problem compiling an application for 2 different platforms: ... Dual Opteron SUN V20z with Suse Professional 10.0 ... Normally you cannot run executables intended for one platform ... However in this case you seem to have a 64 bit and a 32 bit x86 system, ...
    (comp.os.linux.development.apps)