Yes and no. This is not a simple, but not generally a good idea, but you can do it for finite, constant sizes and for constant characters. There are many ways to do this with the C preprocessor. Here is one of them:
#define DUP(n,c) DUP ## n ( c )
#define DUP7(c) c c c c c c c
#define DUP6(c) c c c c c c
#define DUP5(c) c c c c c
#define DUP4(c) c c c c
#define DUP3(c) c c c
#define DUP2(c) c c
#define DUP1(c) c
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%s\n", DUP(5,"-"));
printf("%s\n", DUP(7,"-"));
return 0;
}
, , () . n 'c' DUP ( ). Boost.Preprocessor , (ab) C/++, . Boost ++, C.
, C-:
char* dupchar(int c, int n)
{
int i;
char* s;
s = malloc(n + 1);
if (s != NULL) {
for(i=0; i < n; i++) s[i] = c;
}
return s;
}
, memset, @Jack.