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)

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.

Okey, i suspected that was the case.
Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.