Jump to content
  • Advertisement

Archived

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

Lash

C++ gone crazy

This topic is 5836 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 going mad tring to make this program. I''m just learning c++, so it could just be that there''s something I don''t know. I''ve reduced the code down to what I listed below, but i still can''t see whats wrong with it: ----------------------------------------------- #include <iostream.h> void GetOctets(char* szIP, char& a, char& b, char& c, char& d); int main(void) { char a = 0; char b = 0; char c = 0; char d = 0; char szIP[] = "12.0.253.5"; cout << "made it"; cout << szIP; GetOctets(&szIP[0], a, b, c, d); cout << a << "." << b << "." << c << "." << d; return 0; } ----------------------------------------------- When I run this code, the consol window pops up but nothing is displayed. If comment out ''GetOctets'', the code runs fine. And it doesn''t work any time I try to make a call to my own funtions. My head hurts

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I used to have the same kinda problem too when I was learning c++. Try doing:
"cout << a << "." << b << "." << c << "." << d << endl;", or
"cerr << a << "." << b << "." << c << "." << d << endl;"

Share this post


Link to post
Share on other sites
EDIT: lol I found the problem. My loop in the GetOctets function wasn't exiting, duh

[edited by - Lash on June 25, 2002 11:30:18 PM]

Share this post


Link to post
Share on other sites
Show us the code for GetOctets. This seems to be where your problem is. [edit] Never mind.

Also, just FYI, when you declare an array, the array name by itself is a pointer to the first element in the array. So when you call GetOctets, you can just pass szIP instead of &szIP[0] (which is perfectly legal, it's just unneccessary).

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

[edited by - Chem0sh on June 25, 2002 11:33:34 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just thought I''d point out some redundancy in your code.

GetOctets(&szIP[0], a, b, c, d);

is equivalent to

GetOctets(szIP, a, b, c, d);

since &a is equivalent to &*(a+i), which is equivalent to a+i. In this case i is 0, so the final result is a.

Share this post


Link to post
Share on other sites
quote:
Original post by Lash
#include <iostream.h>

Whatever learning resource you are using, it is teaching you to use the wrong headers. The correct header in this case is <iostream> - i.e. without the ".h".

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!