Thread: Ping Question

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    2

    Ping Question

    Hi all, well basically here's the problem.
    I need my ping program to read a line from a text file in the following format:
    Code:
    server_address port
    
    Example:
    127.0.0.1 80
    Then display the output once it has been pinged etc.

    The code im using so far consists of:
    Code:
    #include <iostream.h>
    #include <windows.h>
    void main()
     { 
    char target[50];
    char pSize[5]; 
    char cmdline[67] = "ping -t -l "; 
    
    cout<<"::Pinger::\n\n";
    cout<<"Enter Host Address: "; 
    cin.get(target, 50); 
    cin.ignore(80, '\n');
    cout<<"Ping Packet Size (Maximum Of 5 Digits): "; 
    cin.get(pSize, 5);
    cin.ignore(80, '\n'); 
    strcat(cmdline, pSize); 
    strcat(cmdline, " ");
    strcat(cmdline, target); 
    system(cmdline);
     }
    Any help is appreciated
    Last edited by dem0n; 01-11-2005 at 08:12 AM.

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    check out a tutorial on fstream, it is what you need for file i/o

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    2
    It's not so much the file i/o it's the code for the ping that im more concerned about

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Do you want to execute the ping utility or re-write it?

    If the former: FAQ: Run a program from within a program

    gg

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Unless I'm understanding your code and intent wrong. Perhaps what you want to do is use a pipe to ping so that your program both handles input and output of it so that you can parse what ping outputs. If so, look into popen().

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I believe I did misread the intent of your "problem".

    If you're running this in a *nix environment, search these boards for popen() examples.

    From the looks of your command line parameters, it seems that this will be running in a Windows environment:
    Creating a Child Process with Redirected Input and Output

    Since you're using the -t option, you will also find GenerateConsoleCtrlEvent() usefull.

    gg

  7. #7

  8. #8
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    I think you misunderstood the intent again codeplug. People use void main just until they make a release of actual importance. Same thing with iostream.h. The indentation may have also been for the same reason. If not, then the thing to do is just to download a compiler that does it for you, such as Dev C++.

    BTW, what's gg stand for?

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I think you misunderstood the intent again codeplug.
    Informing users of this forum that: "void main is wrong", "iostream.h is not standard", and that using proper indentation will help prevent misaligned braces (as the linked thread infers) - is hardly a misunderstanding.

    It's my RL initials.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ping script doesn't work?
    By userpingz in forum C Programming
    Replies: 3
    Last Post: 05-31-2009, 07:53 PM
  2. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  3. ping client
    By cpp_is_fun in forum C Programming
    Replies: 4
    Last Post: 11-29-2006, 12:44 PM
  4. Ping! (Short Question)
    By Lurker in forum Tech Board
    Replies: 8
    Last Post: 11-28-2003, 02:49 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM