#include #include #include #include /// Prints *str* *times* to standard output. int repeat(const int times, const char* str) { for (int i = 0; i < times; ++i) printf("%s", str); return printf("\n"); } /// Concatenates strings from *strv*. User needs to free allocated string. char* concat(const int strc, const char* strv[]) { assert(0 < strc); int i; int len = 0; for (i = 0; i < strc; ++i) len += 1 + strlen(strv[i]); char* const str = malloc(len); str[0] = 0; char* ptr = stpcpy(str, strv[0]); for (int i = 1; i < strc; ++i) { *ptr = ' '; *++ptr = 0; ptr = stpcpy(ptr, strv[i]); } return str; } int main(const int argc, const char* argv[]) { if (3 > argc) return 1; const int times = atoi(argv[1]); if (1 > times) return 1; const char* str = concat(argc - 2, &argv[2]); return repeat(times, str); }