I have tried to write a function in C that duplicates a string n times. Below is my code, but this does not work. Can someone help me and tell me where I am making a mistake? It should come out something like this:
Input: 4 House Output: HouseHouseHouse
char * repeat(char *str, int times)
{ char *ret = calloc(times, (strlen(str) + 1));
while (times-- > 0)
strcat(ret,str);
char *b;
b = repeat(str,times);
printf("%s",b);
return 0; }