Macro for concatenating two strings in C -


I am trying to define a macro that assumes 2 strings and a space between them Joins back together It seems that I can use any character which I want apart from space, for example:

  #define conc (str1, str2) # str1 ## # str2 # Define space_conc (str1, str2) conc (str1, -) ## # straw2 space_ncc (iden, oop);  

space_conc back "idan-oop"

Let me back "idan oop", some suggestions?

try it

  #define space_conc (str1, str2) # Using the string '##', adding symbols is not done for strings, wires can be sequated simply in C, and the compiler will add them. , Which is what this macro does. First turns the strobe into strobe and straight 2 (if you use it like the  space_conc (hello, world) ) and they are used by each other Near sir This is inbetween in space, string, the resulting extension will be understood by such compiler. 

  "hello" "" "world"  

Edit

## The macro extension is used in this way, we say that you have

  #dumb_macro (a, b) ##b  

The result of dumb_macro (hello, world)

  helloworld  

which is not string But there is a symbol and you will probably end up with an undefined symbol error saying 'helloworld' does not exist unless you define it before. It would be legal:

  int helloworld; Dumb_macro (Hello, World) = 3; Printf ("helloworld =% d \ n", helloworld); // & lt; - will print 'helloworld = 3'  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -