string variables in system commands

This is a discussion on string variables in system commands within the A Brief History of Cprogramming.com forums, part of the Community Boards category; how do you put string variablesinto system commands? this is what I have tried tell me what I am doing ...

  1. #1
    Unregistered
    Guest

    string variables in system commands

    how do you put string variablesinto system commands?
    this is what I have tried tell me what I am doing wrong.

    #include <iostream.h>
    #include "apstring.h"
    int main()
    {
    apstring var;
    char cmd[200];

    getline(cin,var);
    sprintf(cmd,"start ",var)
    system(cmd);
    }

    also what is the cmd[200], y wont it work in double variables? what is the 200 mean? I dont get it please please help me

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    The string you scan in using getline() is not getting printed into the 'cmd' string because you are not printing it into the 'cmd'. Instead of this:

    sprintf(cmd,"start ",var);

    Try this:

    sprintf(cmd,"start %s",var);

    char cmd[200]; means that are created a variable named 'cmd', which is a character array with the size of 200 bytes. This means that you can use 'cmd' to store any type of string up to and including 199 characters + the NULL byte
    to terminate the string.

    Hope this helps.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3
    Unregistered
    Guest

    thanx

    thank you very much, that was very helpfull

  4. #4
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    No problem, dude
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM

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