0

Hi!

I'm pretty new to C and have to write something that handles strings.
I have some experience with python and C++ but i find C string handling pretty strange/ugly.

Is the following code really the best way to put together a string containing multiple strings?

strcat(string1, string2);
    strcat(string1, string3);
    strcat(string1, string4);
    strcat(string1, string5);

In python i would do something like:

string1 = "%s" + string3 + "%s" % (string2, string4)
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by laserlars
0

Yes, strcat is standard. Although, make sure you have enough space in string1 first.

I don't know anything about Python, however I would believe that it's some built in feature. In C++, this is achieved through operator overloading. C does not have these features, and you therefore have to work directly with pointers and arrays like this.

Edited by GuitarComet: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.