-
Network Talk tool help
The question is:
What i need to know is how i can put a variable into a function..which is System("");
but for a more detailed question please read on below
Hi im new to C++ but do know (html,asp,php,mysql,javascript) all the major internet ones so i have a coding background. My question is that im trying to make a basic program to later become more in depth but what it is to do is take a typed in message then send it to another computer but before even getting to this far i have stummbled. im using the command what i need inside the system command is
Code:
net send pcname string
In case your lost already this is what i have already
Code:
#include <iostream.h>
#include <stdlib.h>
int main(void)
{
char string[256];
char string2[256];
cout<<"Please enter your Message to pcname:";
cin.getline(string, 256, '\n');
cout <<"You entered: "<<string;
cout <<"\n\n";
system("net send pcname" <<string);
system("Pause");
return 0;
}
its getting the bit in the system part to work
it should basically read
Code:
System("net send pcname HELLO WORLD");
HELLO WORLD being whatever string is.
After all that what i need to know is how i can put a variable into a function..which is System("");
Sorry if ive confused anyone but any help will be MUCH appreciated
Thanks
Chris Ella
-
Look up the string related functions. Specificly strcpy. While you're at it, read up on the rest of the string functions also.
Quzah.
-
or something like:
Code:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string message, command = "net send pcname ";
cout<<"Please enter your Message to pcname:";
cin >> message;
command += message;
cout <<"You entered: "<<message<<"\n\n";
system(command.c_str());
system("Pause");
return 0;
}
the system() function expects a single argument, a const char * - so you have to use the ::c_str() function to obtain that from a string object.
-
Here is a program I wrote to do this. Take a look.
Code:
#include <iostream>
#include <sstream>
#include <string.h>
using namespace std;
int main(void)
{
int nummsg;
int n = 0;
std::stringstream stream;
char ipaddr[20];
char msg[200];
cout << "MeGaBiTe1's Net Send App v0.1\n";
cout << "Enter Computer Name or IP:\n ";
cin >> ipaddr;
cout << "Enter Message:\n ";
cin.getline (msg,200);
cin.getline (msg,200);
cout << "Enter Number of Messages to be Sent:\n ";
cin >> nummsg;
stream << "net send " << ipaddr << ' ' << msg;
system ("PAUSE");
while (n < nummsg) {
std::system(stream.str().c_str());
n++;
}
system ("PAUSE");
return 1;
}
Let's you input how many messages to send also.