Repeat A String | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Nice, Thanks :
// An alternative method

char *repeat(char *string, int repeats){
if(string == NULL || repeats <= 0) return NULL;
int length = strlen(string);
char *s = (char*)calloc(length*repeats+1, sizeof(char));
for(int i = 0; i < repeats; i++){
int j = 0;
while(string[j] != '\0'){
s[i*length+j] = string[j];
++j;
}
}
return s;
}

justcurious
welcome to shbcf.ru