Link to home
Start Free TrialLog in
Avatar of joely2k
joely2k

asked on

Net send command prompt in C++

I am using C to do this program that can send message across LAN and networks...and can send a lot..
using the for loop...heehee
BUt how can I do it in C++??
especially using the FILE open stuff,write in the autoexe batch file..
can someone show me how to do it in C++??
thanks

the program:


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


main()
{
     char ip[100];
     char message[250];
     char cmd[5000];
     int times;
     int choice;
     
     FILE *ptr;
     
     int i;


     printf("---------------------\n");
     printf("Net send bomber..");
     printf("\n");
     printf("---------------------\n");
     printf("\n");
     printf("1.Net Send Bomber\n");
     printf("2.Quit\n");
     printf("Your Selection: ");
     scanf("%d", &choice);
     fflush(stdin);
     

     
     if(choice==1){
          printf("Target (PC Name / IP): ");
          gets(ip);
          printf("Message: ");
          gets(message);
          printf("Number of times: ");
          scanf("%d", ×);

          ptr = fopen("C:\\temp.bat", "w");
          if(ptr)
          {
               for(i=0; i<times; i++)
               {
                    fprintf(ptr, "net send %s %s\n", ip, message);
               }
               fclose(ptr);
               sprintf(cmd, "C:\\temp.bat");    
               system(cmd);    
          }
     }
     else return(0);
     
               
     return 0;
}


Avatar of corduroy9
corduroy9


Are you asking how to make this console program a Windows program?

Or are you asking for the C++ commands that do the same thing as your code does?  (ie instead of using char*, using CString objects?  or instead of printf() using cout?

You can use the same exact code tha you have, put it in a cpp file, and it will work the same.


SOLUTION
Avatar of DavidCrow
DavidCrow

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joely2k

ASKER

yeah corduroy9...
I want it in C++ although I know it can be compile in cpp...
I want the printf change to cout...
cstring and more....
dear David crow...that "w" is for write command for C ...
write the data into the batch file...

I want you all to tell me how to do exactly this same program using C++ commands,strings,types..

thanks..
your help will be highly apprieciated
Lines like

   printf("Net send bomber..");

can be replaced with

   std::cout << "Net send bomber..";

and lines like

   char ip[100];
   gets(ip);

can be replaced with

   std::string ip;
   std::getline(std::cin, ip);

Does that help?
Avatar of joely2k

ASKER

what is the command for writing the message into our autoexec batch file using C++?

ptr = fopen("C:\\temp.bat", "w");

#include <iostream.h> does not support it..
so how??
#include <stdio.h> and #include <iostraem.h>
together will lead to crash?

help me....
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#include <fstream.h>
ofstream file;
file.open("c:\\temp.bat");
file.write(...);
file.close();
Avatar of joely2k

ASKER

thanks alot....this might help me alot man...
I go and try first..
besides that....if got any other solutions or method just put in first ...hehehe
Avatar of joely2k

ASKER

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <fstream.h>



int main ()
{
     char ip[100];
     char message[250];
     char cmd[5000];
     int times;

     ofstream file;

     //net send test..using command prompt..

     cout<<"\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
          <<"\n\n\t\t       Net send tester BETA"
          <<"\n\t\t   Type in the IP/Computer Name"
          <<"\n\t\t     Then input the message.."
          <<"\n\t\tand how many times you wanna send!"
          <<"\n\n\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;

     cout<<"\nEnter IP/Computer name => ";
     cin.getline(ip, 99);
     cout<<"Type message           => ";
     cin.getline(message, 249);
     cout<<"Send how many times    => ";
     cin>>times;

     file.open("c:\\temp.bat", ios::out,0);
     for(int i=0;i<times;i++)
     {
          file.write("net send ip message");
     }

     file.close();
     
     system(cmd);









     getch();
     
     return(0);
}


oh gosh I really dunno how to apply the C++ commands inside the file.write(" ");
cos later I have to relate it in the command prompt
for net send...

//fprintf(ptr, "net send %s %s\n", ip, message);
Tat's I know for C....

and what is the command for C++ in sprintf??
for this statement?

//sprintf(cmd, "C:\\temp.bat");  

In MS VC++, you should use CString objects.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cstring.asp

For sprintf, use the CString::Format() method as follows:

CString sText;
sText.Format( "string = %s number = %d", "test", 99 );

And you can put CString objects inside the file.write() command.

Sounds like you should buy/borrow a intro to C++ book.  It will have all kinds of examples for you.


No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points split between corduroy9 and DavidCrow

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (https://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer