[Dev-C++] execution of a string with system()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Simon J. <el...@op...> - 2002-09-18 14:29:01
|
Hello everybody,
I tried to write a programm which does execute some dos command (like tracert, ping etc.) with an ip.
At first, I created a string (#include <string>), but when I tried to execute it with the system()-command, I got the following error (exec=string-Variable):
"cannot convert 'exec' from type string to type 'const char*'"
Finally -after some hours of trying :)- I've got the following solution:
#include <iostream>
#include <stdlib.h>
int main()
{
int i;
char pcno[20];
cout << "Enter the ip to trace:" , cin >> pcno; //enter domain-name of pc (domain-name is supposed to be 8 chars long)
for (i=0;i<8;i++){pcno[i+8]=pcno[i];}; //put the domain name at the end
pcno[0]='t';
pcno[1]='r';
pcno[2]='a';
pcno[3]='c'; //enter the dos-command in the first chars
pcno[4]='e';
pcno[5]='r';
pcno[6]='t';
pcno[7]=' ';
for (i=16;i<40;i++){pcno[i]=' ';};
system(pcno);
system("PAUSE");
return 0;
}
Does someone know an easier solution?
Tanks for your help.
Simon
--
__________________________________________________________
Download the FREE Opera browser at www.opera.com/download/
Free OperaMail at http://www.operamail.com/
Powered by Outblaze
|