string variables and system commands part 2

This is a discussion on string variables and system commands part 2 within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Im trying to get a string variable into a system command but it wont work, whats wrong with my code? ...

  1. #1
    Unregistered
    Guest

    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-";
    cin.getline(comp,256,'\n');cin.get();
    cout<<" Enter message: ";
    cin.getline(message,256,'\n');cin.get();
    sprintf(cmd,"net send 008-%s",comp," %s",message);
    cin.get();

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

    printf( const char* formatstring, ... )


    So:

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

    should be

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

    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 Cprogramming.com
    Replies: 3
    Last Post: 10-24-2001, 12:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21