Suppose I want to generate ------
, with only -
, is there a C macro to generate repeated string ?
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
use boost, E.g
Not in C standard.You need to write your own implementation.
EDIT:
something like this:
Yes and no. It's not simple, and 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:
It's not pretty, and only useful when you really want the string to be stored as static (constant) data. Both the
n
and 'c' parameters toDUP
have to be a constants (they cannot be variables). The Boost.Preprocessor module has a lot of good information for how and when to (ab)use the C/C++ preprocessor like this. Although Boost is a C++ library, the preprocessor information is largely applicable to straight C.In general, you're much better off doing this in normal C code:
or, use
memset
, as @Jack suggested.