I am trying to pass command line arguments which I then concatenate appropriately to generate shell commands so that I can run them using system() (I know it is not advisable and there are better ways but I have been asked to do it in this way only). But there's some problem in concatenation of the strings that I pass Here is the code (I have printed everything at every step to get a clear understanding and no I haven't yet written the system() calls,first I need to sort this concatenation out):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char* path=argv[1];
char* oldName=argv[2];
char* newName=argv[3];
char* command1="cd ";
char* command2="ren ";
printf("\n\n%s\n%s\n%s\n%s\n%s\n",command1,command2,path,oldName,newName);
strcat(command1,path);
printf("\n\n%s\n%s\n%s\n%s\n%s\n",command1,command2,path,oldName,newName);
strcat(oldName," ");
strcat(oldname,newName);
printf("\n\n%s\n%s\n%s\n%s\n%s\n",command1,command2,path,oldName,newName);
strcat(command2,oldName);
printf("\n\n%s\n%s\n%s\n%s\n%s\n",command1,command2,path,oldName,newName);
return 0;
}
However after concatenating command1 to path everything gets messed up.