1

I want to create a string in char array from concatenation in C
Example I want to do something similar to this

...
...
#define version "1.0"

char message[] = "Software version" + version + "\n"
...
...  

Thanks

4
  • 1
    Get rid of the +s: consecutive string constants get concatenated by the compiler. Commented Sep 25, 2015 at 12:30
  • 1
    Preprocessor macros traditionally have all upper-case names, to distinguish them from e.g. variable and function names. Commented Sep 25, 2015 at 12:33
  • @Kninnug wow I wonder how I didn't think of this before :) Commented Sep 25, 2015 at 12:38
  • 1
    @JoachimPileborg I know But I decide to drop this because I love the camelCase and I hate too much underscores. Commented Sep 25, 2015 at 12:39

1 Answer 1

1

C has a feature to concatenate string literals during compilation, by just having white-space between the literals. Meaning you could do e.g.

char message[] = "Software version" version "\n"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.