PDA

View Full Version : string variables in system commands



Unregistered
10-23-2001, 06:14 PM
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

Engineer
10-24-2001, 11:04 AM
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.

Unregistered
10-24-2001, 11:13 AM
thank you very much, that was very helpfull

Engineer
10-24-2001, 12:36 PM
No problem, dude