Skip to content

Instantly share code, notes, and snippets.

@louipc
Created October 8, 2018 00:53
Show Gist options
  • Select an option

  • Save louipc/be8d85357805c9322ce38786ee65aca6 to your computer and use it in GitHub Desktop.

Select an option

Save louipc/be8d85357805c9322ce38786ee65aca6 to your computer and use it in GitHub Desktop.
/*
Repeat given string
*/
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
char *repeat_str(int count, const char *src) {
char *dest = malloc((strlen(src)*count)+1);
for (int i=0; i < count; i++) {
strcat(dest, src);
}
return dest;
}
int main() {
char input[2^13];
int x;
printf("Repeat number: ");
scanf("%d", &x);
printf("Repeat string: ");
scanf("%s", input);
printf("%s\n", repeat_str(x, input));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment