NaN
NaN

Reputation: 3591

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

Upvotes: 0

Views: 500

Answers (1)

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143071

You can only concatenate string literals at compile time.

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

Upvotes: 5

Related Questions