parsing error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Medvedev

    parsing error

    when i try to read the first byte from an EXE file it's give different
    results
    code:
    FILE *me,*u;
    char buf_me[1];
    char buf_u[1];

    me= fopen(argv[0],"rb");
    u= fopen(argv[1],"rb+");

    fread(buf_me,si zeof(char),1,me );
    fread(buf_u,siz eof(char),1,u);

    printf("%s\n",b uf_me);
    printf("%s\n",b uf_u);

    ----
    when you run this code and put EXE file as an argument , the program
    will print
    M
    MM

    why it double the byte in the second time
  • Ian Collins

    #2
    Re: parsing error

    Medvedev wrote:
    when i try to read the first byte from an EXE file it's give different
    results
    code:
    FILE *me,*u;
    char buf_me[1];
    char buf_u[1];
    >
    me= fopen(argv[0],"rb");
    u= fopen(argv[1],"rb+");
    >
    fread(buf_me,si zeof(char),1,me );
    sizeof(char) is one by definition.
    fread(buf_u,siz eof(char),1,u);
    >
    printf("%s\n",b uf_me);
    printf("%s\n",b uf_u);
    >
    These to lines invoke undefined behaviour, buf_me and buf_u are not null
    terminated C style strings.

    c.l.c is a better place for pure C questions.

    --
    Ian Collins.

    Comment

    Working...