I am trying to merge multiple string array tokens into one, for example:
char* args = { "zero" , "one', "two"}
Noting that args is not a set size, it could be 1 or 100
I want to make a new array
char* array ={"one two"}
with the spaces in between.
I tried this:
char* array;
int i=1;
for(i=1; i< sizeof(args)-1 ; i++){
strcat(array, args[i]);
}
but kept getting a segmentation fault.
This is the code I am using, need to add function that combines all of my args from 1 (not zero since arg[0] has a command) to whatever size:
else if ( (args[1] != NULL) && (strchr(args[1], '=') != NULL) ) {
memcpy(aliasCommands[aliasCount], args[1], 512 );
printf("Save Alias\n");
printf("Alias Added : %s\n", aliasCommands[aliasCount]);
aliasCount++;
printf("Alias Number : %d\n", aliasCount);
}
Instead of only args[1], I want to pass args[1] space args[2] and so on
Lets say that
args[1]={"command='ls"}
args[2]={"cd'"}
and so on, args could be up to 512. I want to pass them all as one string in
aliasCommand[aliasCount] = {"command='ls cd'"}