If you to want make a print of N arguments, you can do
int i = 1 ; // first parameter is a program name
while(i < argc )
{
printf("%s",argv[1]);
i++;
}
But if you want to use a string in other processor,you would really concatenate then. Maybe with:
char* string_result;
int i = 1;
int size_total = 0;
bool space_needed = false;
while(i < argc) { // argc contain the number of arguments
size_total += strlen(argv[i])+1; //+1 for a new space each time.
i++;
}
if(i > 2) {
space_needed = true;
size_total -= 1; //no need for space at end of string
}
string_result = (char*)malloc((size_total+1)*sizeof(char));
string_result[0] = 0 ; // redundant?
i = 1;
while(i < argc) {
strcat(string_result,argv[i]); // caution to concatenate argv string, memory of OS.
if(space_needed && (i+1) < argc)
strcat(string_result, " "); //space so it looks better.
i++;
}
//free pointer when done using it.
free(string_result);
systemor something, this is a very bad approach. Instead useexecvor similar.