By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,120 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,120 IT Pros & Developers. It's quick & easy.

Dynamic file names when using system(); function

P: 3
i'm trying to make an command shell or something like that, so i'm using system("cat archivo.txt"); for example, but what i want is todo something like system("cat"+variable), is there any way to do this?
Mar 24 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
i'm trying to make an command shell or something like that, so i'm using system("cat archivo.txt"); for example, but what i want is todo something like system("cat"+variable), is there any way to do this?
in C you can put your command in a char array and concatenate the variable on the end, e.g.
Expand|Select|Wrap|Line Numbers
  1.     char *c = "*.c";
  2.     char dir[20]="dir ";
  3.     system(strcat(dir, c));                                         /* call system */
  4.  
system() gets the parameter "dir *.c"

in c++ you could use string variables
Expand|Select|Wrap|Line Numbers
  1.     string c = "*.c";
  2.     string dir ="dir ";
  3.     system((dir + c).c_str());                                         /* call system */
  4.  
Mar 24 '07 #2

P: 3
thanks, that's all i want to know!
Mar 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.