Hi, what would be a easy way of taking chars from the BEGINNING of a string, and placing them in another variable, ensuring that they are removed from the original string, ideally at the same time?

basically, say i have 2 strings, string1 and string2.

string1 contains "helloworld"

string2 is blank.

I want to take the 'hello' from string1 and place it in string2, so at the end we get:

string1 = "world"
string2 = "hello"

how would I do this? I'd ideally like to scan along the string for a particular character, and chop the beginning off upto that char.

Look up strncpy() . Wouldn't it be easier to copy the end of the string instead? That way you don't have to copy the beginning and move the end of the original to the beginning.

No, I *have* to remove chars from the beginning of the string, sorry.

No need to be sorry. Instructors like you to do things the hard way.

Just look up strncpy() .

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.