#include <stdlib.h>
#include <string.h>
#include <stdio.h>

char * repeat_str(size_t count, const char * src)
{
   size_t len = strlen(src);
   char * result = (char *) malloc(sizeof(char) * (len * count + 1));
   
   if (result == NULL) {
   	return NULL;
   }

   for(size_t i = 0; i < count; i++) {
   	strncpy(result + i*len, src, len);
   }
  
   result[count * len] = '\0';
   return result;
}

int main(void)
{
	char * result = repeat_str(3, "hello ");
	if (result == NULL) {
		printf("OOM\n");
		return EXIT_FAILURE;
	}
	int success = strcmp(result, "hello hello hello ") == 0;
	printf("Result: '%s' (success: %d)", result, success);
	return success ? EXIT_SUCCESS : EXIT_FAILURE;
}