Jump to content

[C] Use a struct in a fseek()

- - - - -

  • Please log in to reply
3 replies to this topic

#1
stefanostefano

stefanostefano

    Newbie

  • Members
  • Pip
  • 3 posts
Hi guys, this is my first post. I'm a guy and I like programming C. I study at university and I hope to find here friendly people :)

Now I've got this problem.

I've constructed a struct like this:

struct alfa
{
uint32_t beta1;
uint32_t beta2;
};
struct alfa gamma;
Then I need to move cursor with an fseek(), so:

fseek(file,gamma.beta1,SEEK_CUR);

the result is wrong...but why?!

gamma.beta1 is not like a normal int?! how can I do to move cursor about beta1 value?

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Ok...by "cursor" do you mean the cursor on the screen? You can't do that by fseek'ing. Otherwise I have no idea what you meant.
sudo rm -rf /

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
@Dargueta, Probably an accidental reference to something from another language, he means position.

stefanostefano said:

the result is wrong...but why?!

Where did you initialize gamma.beta1 in your script? How is the result "wrong"?, you left out a lot of information.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
@Nullw0rm: I've seen this problem before, so I had to ask.
@stefanostefano: You have to set gamma.beta1 to some reasonable value before using it in fseek(). Otherwise, who knows what bizarre value it'll hold. Could be -234874 for all we know.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users