Follow us on Twitter!
Capitalism is an Island of wealth in a sea of poverty
Thursday, April 17, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 29
Guests Online: 27
Members Online: 2

Registered Members: 82815
Newest Member: medjiking
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 14:21
I recently found the ability to use the system () command in programs through an online tutorial however I am trying to figure out how to incorporate strings and intergers in the system command with the system functions. In this 30 second code I have quickly devised as an example, I am attempting to ping the ipaddress that the user has entered, the code is working however it displays an error which seems to mean it is not using the ipaddress i am entering. I could do with some help here guys :(

Code
#include <iostream>

using namespace std;

string ipaddress;
string ping;

main(){
cout<<"Welcome to the pinger v1"<<endl;
cout<<"please enter an IP address"<<endl;
cin>> ipaddress;
cout<<"please enter ping to ping the IP address or again to re-enter an IP"<<endl;
cin>> ping;
if (ping == "ping"){
system ("ping ipaddress");
}
else if (cout<<"woah");
 {
        cout<<"please enter and IP address"<<endl;
cin>> ipaddress;
}
}



Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 14:45
you need stdlib Smile also why not use sprintf to format it. I'm no c++ programmer though




Edited by on 17-05-10 14:46
Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 16:21
Ah, I really need to look into what commands require what librarys and i have never used the sprintf command before - guess i've got a lot to learn yet aye! Pfft
Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 16:29
It's basically the same has printf but it puts it in a char array which you could pass to system Smile


Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 19:58
@wolfmankurd: he really doesn't need that.

@OP: is that supposed to be pseudocode or not? Because if not, then you really need to relearn a lot of things, heck, even if it is pseudocode you'll need to brush up on how the flow of a program works... and also brush up on your style (poor int and return being abandoned hurts me at my heart).

Oh and try to leave off the system command if possible. Some people get addicted to it and do disgusting things like system("pause")


Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 20:31
COM wrote:

Oh and try to leave off the system command if possible. Some people get addicted to it and do disgusting things like system("pause"Wink


I was speaking to someone about not using system("pause"Wink, but I couldn't come up with a good replacement to stop the window closing once the program exits in cmd. What would you recommend?


Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-05-10 20:53
wolfmankurd wrote:
I was speaking to someone about not using system("pause"), but I couldn't come up with a good replacement to stop the window closing once the program exits in cmd. What would you recommend?

cin.get();

or, if they're working with C only, then I think getchar();

I presume they've already tried this though and can't get it to stop and thus have turned to system("pause");, so I'll just go ahead and explain the reason as to why their program won't stop and what to do bout it.

If they read in with some standard cin for instance, then it's going to read in up to the return value, which'll be stuck in the buffer. Next time you try to read in, if you use something like cin.get() which isn't that needy and is satisfied with just a return value, it'll take that and be done. So this means that you can pause it with two cin.get() or two getchar() functions after each other.
However, the better thing to get used to is to follow every cin or similar which you know leaves a return value in the buffer, with a cin.get(), getchar() or cin.ignore() so the buffer will always be clean and empty.

Hope that helps and explains it well enough, it's an easy beginner's mistake to make and I've had to explain it a billion times.

Edit: I assume of course that you meant "how to stop the window from closing once the program has reached its end", because once a program exits then there's obviously not much you can put into it that should stop it from closing. If you want the pretty black box to be there after the program's finished I recommend actually running it from there to begin with.




Edited by on 17-05-10 21:35
Author

RE: C++ Using System ()


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 18-05-10 01:59
That's what I suggested he wanted it to stay open so people who didn't know how to use command line could see the results of the program.