Ping a variable?

This is a discussion on Ping a variable? within the Windows Programming forums, part of the Platform Specific Boards category; Lets say... I wanted to ping an IP. I know this can be done in CMD, or C++ very easily, ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    use std::string
    build you whole string before calling system
    pass command.c_str() to system
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 12:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  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, 03:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21