Link to home
Start Free TrialLog in
Avatar of xiuxiull
xiuxiull

asked on

How can I copy the string from a specified position in C?

In order to rotate the 2 last charaters in a word, I use the following way
For example, s[] = "Hello";
I would like to copy "lo" to another array with strcpy and then use strcat to concatenate the string "Hel" after "lo" to form "loHel".But I can only copy the whole string to another array, I don't know how to specify an exact position. Thanks, I'm just newbie in C.
Avatar of gj62
gj62

use memcpy...

char orig[] = "Hello"
char newStr[6];

memcpy(newStr, orig[strlen(orig)-2], 3);/* 3 to copy the null*/
memcpy(newStr[2], orig, strlen(orig)-2);
ASKER CERTIFIED SOLUTION
Avatar of Nosfedra
Nosfedra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
xiuxiull:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.