parsing error

Discussion in 'C++' started by Medvedev, Jul 1, 2008.

  1. Medvedev

    Medvedev Guest

    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,sizeof(char),1,me);
    fread(buf_u,sizeof(char),1,u);

    printf("%s\n",buf_me);
    printf("%s\n",buf_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
    Medvedev, Jul 1, 2008
    #1
    1. Advertising

  2. Medvedev

    Sleipnir Guest

    Put this instead:

    printf("%c\n",buf_me); // %c
    printf("%c\n",buf_u); // %c


    You can assume your variables are one to the other into the memory. When you
    send a string to printf, it's gonna write it untill it finds the character
    '\0' which is not present here.



    "Medvedev" <> a écrit dans le message de
    news:...
    > 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,sizeof(char),1,me);
    > fread(buf_u,sizeof(char),1,u);
    >
    > printf("%s\n",buf_me);
    > printf("%s\n",buf_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
    Sleipnir, Jul 1, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    873
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    578
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    608
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    431
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    728
    John Levine
    Feb 2, 2012
Loading...

Share This Page