Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

A very strange problem reading a file....

cignox1cignox1 Posts: 33Member
Hi, I've currently a very strange problem trying to read data from a file. In this file there is a sequence of objects of this form:
-int
-int
-char //<--| Packed in a single integer by the compiler
-char //<--|
-int
-string

The first char rapresents the day field of a date.

Ok. Most of times the program writes and reads its files without errors, but this time, when it tries to read it, it reads some objs and then, just before the first char, an End Of Files occours. The file seems to be correct. Then I opened it with an hex editor, then I changed this char (= 1A) with 1C. And then the program run! I just changed the day and the End of file didn'appear! What do you think about?

Comments

  • gustavosserragustavosserra Posts: 201Member
    What package is that? In most architectures int are 4 bytes long. And show us your code.

    : Hi, I've currently a very strange problem trying to read data from a file. In this file there is a sequence of objects of this form:
    : -int
    : -int
    : -char //<--| Packed in a single integer by the compiler
    : -char //<--|
    : -int
    : -string
    :
    : The first char rapresents the day field of a date.
    :
    : Ok. Most of times the program writes and reads its files without errors, but this time, when it tries to read it, it reads some objs and then, just before the first char, an End Of Files occours. The file seems to be correct. Then I opened it with an hex editor, then I changed this char (= 1A) with 1C. And then the program run! I just changed the day and the End of file didn'appear! What do you think about?
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    : What package is that? In most architectures int are 4 bytes long. And show us your code.
    [blue]But a char is just a 1-byte integer.

    what compiler and operating system are you using?
    [/blue]

    :
    : : Hi, I've currently a very strange problem trying to read data from a file. In this file there is a sequence of objects of this form:
    : : -int
    : : -int
    : : -char //<--| Packed in a single integer by the compiler
    : : -char //<--|
    : : -int
    : : -string
    : :
    : : The first char rapresents the day field of a date.
    : :
    : : Ok. Most of times the program writes and reads its files without errors, but this time, when it tries to read it, it reads some objs and then, just before the first char, an End Of Files occours. The file seems to be correct. Then I opened it with an hex editor, then I changed this char (= 1A) with 1C. And then the program run! I just changed the day and the End of file didn'appear! What do you think about?
    : :
    :
    :

  • dwgeblerdwgebler Posts: 190Member
    1A (26 dec) is the ASCII code for EOF, is it not?

    : Hi, I've currently a very strange problem trying to read data from a file. In this file there is a sequence of objects of this form:
    : -int
    : -int
    : -char //<--| Packed in a single integer by the compiler
    : -char //<--|
    : -int
    : -string
    :
    : The first char rapresents the day field of a date.
    :
    : Ok. Most of times the program writes and reads its files without errors, but this time, when it tries to read it, it reads some objs and then, just before the first char, an End Of Files occours. The file seems to be correct. Then I opened it with an hex editor, then I changed this char (= 1A) with 1C. And then the program run! I just changed the day and the End of file didn'appear! What do you think about?
    :

  • cignox1cignox1 Posts: 33Member
    I'm stupid!!! 1A is the ASCII code for EOF!! And on my system, if not specified, the default reading mode for fopen is text mode. I simply specified "b" and everything run OK! Thank you ver much! (I'm stupid, I'm stupid,...;-)

    : 1A (26 dec) is the ASCII code for EOF, is it not?


Sign In or Register to comment.