Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am using the "sytem("net send") command in a C++ program I am writing. I want the actual command that is sent to the consol to be "net send user message". Where user is a variable and message is a variable. The problem is if I type:
string user = ryan;
string message = hi;
system(net send user message);it gives and error abotu nto having quotes.
If i type:string user = ryan;
string message = hi;
system("net send user message");It tries to send "message" to "user".
And also ("net send" user message) dosn't work.
So what do i nedd to do?
-Ryan Adams
Ryan's
Custom Cables

Try this!
char* l_lpszUser = "ryan";
char* l_lpszMsg = "hi";
char l_szCommand[50];ZeroMemory(l_szCommand, sizeof(l_szCommand));
sprintf(l_szCommand, "net send %s %s", l_lpszUser, l_lpszMsg);
system(l_szCommand);Sohaibi

Ok here is my code:
#include <iostream.h>
#include <stdlib.h>int main()
{system("net start messenger");
int number;
char* l_lpszUser;
char* l_lpszMsg;
char l_szCommand[50];cout << "Enter user name: ";
cin >> l_lpszUser;cout << "Enter message: ";
cin >> l_lpszMsg;int counter=1;
while ( counter <= 100) {
ZeroMemory(l_szCommand, sizeof(l_szCommand));
sprintf(l_szCommand, "net send %s %s", l_lpszUser, l_lpszMsg);
system(l_szCommand);counter++;
}
system("net stop messanger");
system("PAUSE");
return 0;
}It still gives me errors though. Specifically
"
24 h:\ryan_a~1\program.cpp
implicit declaration of function `int ZeroMemory(...)'
25 h:\ryan_a~1\spam.cpp
implicit declaration of function `int sprintf(...)'
"What is wrong?
-Ryan Adams
Ryan's
Custom Cables

Get rid of the ZeroMemory line. It's not necessary in this case and ZeroMemory is not a standard C++ function. It must be specific to Sohaib's compiler or environment.
It's not necessary to zero out the string buffer before you write a string to it.
Once you get rid of the ZeroMemory() call, your code should work.
Be sure to come back and let us know if our suggestions helped!

That gets rid of the errors and it compiles, but the program crashes when I try to run it. I think I am doing somethign wrong.
-Ryan Adams
Ryan's
Custom Cables

Sorry, I didn't look over the whole program very closely and missed some other things.
Change these two definitions:
char* l_lpszUser;
char* l_lpszMsg;to something like:
char l_lpszUser[50];
char l_lpszMsg[50];Make each size big enough to hold what input you expect.
What you have now for both variables is char pointers. The problem is two-fold. First, since you declared them inside the function (main) and did not initialize them, they will have some undetermined value. The value of these two variables will be whatever happens to be in the memory of where they are allocated. So when you use cin to input something for them, one of two things is happening. 1-the value of the variable is an invalid address so the program crashes or 2- the address is OK (very lucky) but writing the input to that address overwrites something important so the program crashes. The third case (which does happen sometimes) is that the address is OK and the memory overwritten doesn't cause any problems, so you don't know that this is wrong.
I assume that you fixed the sprintf error, but if not, you need to include <stdio.h> for that.
Be sure to come back and let us know if our suggestions helped!

#include <iostream>
#include <string>
using namespace std;int main()
{string user, message, sendstring;
char buffer[50];system("net start messenger");
cout << "Enter user name: ";
cin.getline(buffer, 50);
user = buffer;cout << "Enter message: ";
cin.getline(buffer, 50);
message = buffer;sendstring = "net send " + user + " " + message;
system(sendstring.c_str());
system("net stop messenger");system("Pause");
return 0;
}

Hi egkenny,
I'm reading along here, trying to learn.
I tried to compile the code in #6.
I'm using Turbo c++, so that may be an issue.
The first couple of errors:
Unable to open include file 'iostream'
Unable to open include file 'string'were eliminated by adding .h
Now we're down to
Error egkenny.cpp 5: Type name expected
Error egkenny.cpp 10: Undefined symbol 'string' in function main()
Error egkenny.cpp 10: Undefined symbol 'user' in function main()and about a dozen more.
Maybe TC++ 1.0 is not up to this.
TIA
M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |