For example, i have char variable = "This is a simple text";
and i need to put word "Very" between "a" and "simple"
How to do it using standart C library?

Recommended Answers

All 5 Replies

For example, i have char variable = "This is a simple text";
and i need to put word "Very" between "a" and "simple"
How to do it using standart C library?

Use strstr library function to search "Very" in the string. If it's found make a room at this point (shift right all chars started from the point with trailing zero byte - a c-string is an array of char, use memmove or write a for loop). Now move "simple" to the free room (by memcpy or memmove - don't forget to append blank after "simple" word).
That's all.
Write the code, debug it then come back on some troubles ;)

strstr is used to find the occurece of first string into the another string which is already defined in the library function.
if "very" is not there in your string you can simply insert in place where you want.

How should i find the place where to put "Very" if i know - it must be before "simple". First, i should find "simple" and then put "Very" before it. But how to do it?

>But how to do it?
Did you not read the answers you've been given? Both of them told you to use the strstr function.

How should i find the place where to put "Very" if i know - it must be before "simple". First, i should find "simple" and then put "Very" before it. But how to do it?

yaa you need to find the specific words such as "a" and "simple" so that in between you need to insert the word "very".

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.