Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STRCAT not working with argv[x]??

Status
Not open for further replies.

evosix

Programmer
Apr 27, 2003
9
AU
Hello all,

Wondering why i cannnot use "strcat(s1, s2)"??
where:

char* s1;
s1 = "ls ";

string s2 = argv[1]; // where argv[1] is "-a" etc.

I want to strcat it so that i can get "ls -a" in one variable to pass into the system() function.

its really puzzling me, as the system() function cant use a string variable as its parameter, and needs a char*??

Anyhelp will be appreciated greatly,

-evosix-

 
[tt]s1[/tt] is a constant variable, as you assign it a constant string. You would first have to allocate some memory, and then [tt]strcpy[/tt] to copy in [tt]"ls "[/tt] into [tt]s1[/tt]. After that, you should be able to use [tt}strcat[/tt] like above.

//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top