Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a string

Status
Not open for further replies.

tsp120

Programmer
May 21, 2003
52
US
I have a situation where I need to take the first 4 characters of a string and change them. Let's say for instance I have these numbers stored in a string:

123456789

What I want to do is take the 1234 and change it to a 4321

Any idea how to do this?

Thanks!
 
N/M, that was really easy. But I have a related issue. I now need to do the same thing but with the last 4 characters of a string. For the problem mentioned above I just used strncpy, however that just does the first characters of size n. What if I want to do this with middle or end characters?

Thanks again!
 
Pick a position.

These two are equivalent
Code:
strncpy( dest, "4321", 4 );
strncpy( &dest[0], "4321", 4 );

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top