Thread: Ping a variable?

  1. #1
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114

    Ping a variable?

    Lets say... I wanted to ping an IP. I know this can be done in CMD, or C++ very easily, but lets say I want to ping it a few times without re-entering the IP or Website. I've made it loop 5 times, but how would I get the person to enter the IP or Website they wanted to ping... For example,
    Code:
    #include <iostream>
    #include <windows.h>
    #include <winable.h>
    using namespace std;
    int main()
    {
    char IP[9999];
    int x = 0;
    cout<<"Enter IP or Website to ping: ";
    cin.getline(IP, 9999);
    cout<<"\n";
    while (x != 5)
    {        
    system("ping" IP );
    x++;
    }
    return 0;
    }
    Doesn't work. How would I ping a variable without having to hardcode it? Thanks,
    Brad.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    use std::string
    build you whole string before calling system
    pass command.c_str() to system
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Thanks, I got it working.
    OS: Windows XP Home Edition SP3, Windows 7 Ultimate Beta Build 7000
    LANGUAGES: C++, VB6
    SKILL: Novice/Intermediate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM