Hello, I'm trying to "import" the perl function called "join", you can see what this function make's here. Now I have this code:
Code:
int join (char str1[], char str2[], char w, char buf[], int size) {
int i,j;
unsigned long totsz;
totsz = sizeof(str1) + sizeof(str2) + sizeof(w);
//check if space is sufficient
if (size <= totsz)
return 0;
for (i=0; str1[i]; i++)
buf[i] = str1[i];
buf[i++] = w;
for (j=0; str2[j]; j++,i++)
buf[i] = str2[j];
buf[i] = '\0';
return 1;
}
int main(void) {
char buf[1000];
if ((join ("lala", "lele", ':',buf, sizeof(buf))) != 0)
printf("Buf = %s\n",buf);
else
printf("There was an error, probaly buffer is too small\n");
return 0;
}
Perfect it works fine, my question is, how do I make possible something like that:
Code:
char joined[100];
joined = join ("lala","lele",':',sizeof(buf));
When I try to create a string in the function, and return it it says returning temp variable don't know what, and I receive a lot of $$$$s.