Thread: string variables and system commands part 2

  1. #1

    string variables and system commands part 2

    Im trying to get a string variable into a system command but it wont work, whats wrong with my code?

    char cmd[200],comp[256],message[256];
    cout<<" Enter computer name: 008-";
    cout<<" Enter message: ";
    sprintf(cmd,"net send 008-%s",comp," %s",message);

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    sprintf follows basic printf syntax:

    printf( const char* formatstring, ... )


    sprintf(cmd,"net send 008-%s",comp," %s",message);

    should be

    sprintf( cmd, "net send 008-%s %s", comp, message );

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Can someone help me understand this example program
    By Guti14 in forum C Programming
    Replies: 6
    Last Post: 09-06-2004, 12:19 PM
  3. Using variables wiht system()
    By Bender in forum C++ Programming
    Replies: 4
    Last Post: 07-31-2004, 10:00 PM
  4. Using Variables with th 'System' command
    By dapernia in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2003, 05:11 PM
  5. string variables in system commands
    By Unregistered in forum A Brief History of
    Replies: 3
    Last Post: 10-24-2001, 12:36 PM