Search code examples
cconcatenationappendansi-c

C append/concat strings "on the fly"


I thought it's possible to concatenate strings (char arrays) in C on the fly.

char* str1= "hello" " " "world";

But when I try the following I'll receive an error message (Too few arguments to function fopen). why?

fopen(*argv ".comp", "r");

I want to concat the argument with an char[] constant - without the strcat indirection. Is this possible?

Like the "string".$var in PHP or the "a string like this" + var in Java


Solution

  • You can only concatenate string literals at compile time.

    Because compiler has no idea what *argv is going to be.