Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Cinnamon

need help to pass pointers with structures

This topic is 5690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m a beginner and I''m doing some test. I''m trying to practice using fonctions, pointers and structures. I did this little program. What I don''t understand is that it compile and build with zero error, but the .exe crash everytime. #include <iostream> #include <windows.h> using namespace std; typedef struct _STATS{ int Experience; int Level; int Attack; int Defence; } STATS; void st(STATS &Hero); int calcul(); void imprime(); void st(STATS &Hero) { Hero.Experience=10; Hero.Level=1; Hero.Attack=3; Hero.Defence=2; } int calcul(int a, int b) { int result; result=a+b; return result; } void imprime(int r) { cout << r << endl; } int main(STATS *Hero) { int result=0; result=calcul(Hero->Experience,Hero->Attack); imprime(result); return 0; } Thank you for your help!

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Cinnamon

int main(STATS *Hero)
{
int result=0;
result=calcul(Hero->Experience,Hero->Attack);
imprime(result);
return 0;
}




Heres your problem. main() can either accept nothing (void) or argc and argv.

int main()
{
}

or

int main(int argc, char** argv)
{
}

Heres a new main function for you:


  
int main()
{
STATS hero;
int result=0;
result=calcul(hero.Experience, hero.Attack);
imprime(result);
return 0;
}


Oh yeah, typedef on structs/classes is a redundant feature from C. You dont need it in C++. And you never seem to call your st() function.

Share this post


Link to post
Share on other sites
quote:
Original post by Cinnamon
int calcul();
void imprime();


It might be that you just forgot to type it in your post, yet your prototypes for calcul() and imprime() do not match their headings (int calcul(int a, int b) and void imprime(int r)). Since you said it compiled with no errors, I guess you typed it wrong; just pointing out though

:::: Lektrix ::::
[ Google || ACCU || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!