Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C

Idiom #266 Repeated string

Assign to the string s the value of the string v repeated n times, and write it out.

E.g. v="abc", n=5 ⇒ s="abcabcabcabcabc"

#include <stdlib.h>
#include <string.h>
char *s = calloc(strlen(v) * n + 1, 1);
for(int i = 0; i < n; ++i) strcat(s, v);
with Ada.Strings.Fixed;
use Ada.Strings.Fixed;
S : constant String := N * V;

New implementation...
< >
tkoenig