This is what I've came up with so far:
Code:
void makeString(char *args[]) {
int j;
char tmpBuffer[MAX_LINE+3];
char *tmpBufferPointer = &tmpBuffer[0];
sprintf(tmpBufferPointer,"%d: ",numOfCommands);
for (j = 0; j < MAX_LINE/2+1; j++) {
if (args[j] == NULL) break;
strcat(tmpBufferPointer, args[j]);
strcat(tmpBufferPointer, " ");
}
}
(MAX_LINE/2 + 1 is the size of args)
I think this will add a space right after the last non null element of args.. but I'm not sure how I can avoid that, since I don't know when args[j] will become null.
Also, is there another way to loop through args without using a for loop? I haven't programmed in C for about 2 years and I remember there used to be some standard method to go through arrays, somehow use pointers? If anyone can jolt my memory that would be great!
Thanks