I need to store the following strings in 3 char * variables in C:
[foo]
[foo]:[bar]
[foo]:[bar]:[tat]
Each individual string such as "foo" is received at one point of time via a char* pointer, the corresponding output string is produced immediately before receiving the second string, and the total number of individual strings is known at all times.
There can be an arbitrary number of strings.
I wrote the following code to print the strings:
for(i=0;i<num;i++)
{
for(j=0;j<=i;j++)
{
printf("[%s]",str[j]);
if(j!=i)
{
printf(":");
}
else
{
printf("\n");
}
}
}
But I am unable to figure out a way of storing the desired output strings in variables, other than writing a messy case-by-case function using strcat() & some additional self-defined functions.
Is there a way to do this, that looks as clean as simply printing the strings?