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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: How do you copy one specific character from a string 2

Status
Not open for further replies.

RoyceyBaby

IS-IT--Management
Mar 23, 2001
22
0
0
Hi all,

Extreme newbie question comming up.

If i have a string

strA="Once upon a time\0";
strB="";

how do I copy say the third character from strA to strB, then maybe the seventh character from strA to strB.

I know it is these darn pointers, but I can't get my head round them yet.

Many thanks,

Royce
 
strB[0]=strA[2];
strB[0]=strA[6]; John Fill
1c.bmp


ivfmd@mail.md
 
if you want to use pointers so :

char *pa // pointer for strA
char *pb // pointer for strB

pa=strA /* pa get the first place of the string it's
equal to pa=strA[0]
so now pa point us at the first place on strA
the same thing we'll do with strB see below. */

pb=strB // pb point the first place at strB

/* let's say that we want the seventh character from strA to strB */

*pb=*(pa+6) /* the content in address pb (* = content) get
the content in address pa+6 */

oneuman@netvision.net.il
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top