-
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 :)
-
check out a tutorial on fstream, it is what you need for file i/o
-
It's not so much the file i/o it's the code for the ping that im more concerned about :(
-
Do you want to execute the ping utility or re-write it?
If the former: FAQ: Run a program from within a program
gg
-
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().
-
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
-
-
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?
-
>> 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