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

c++ beginner

Status
Not open for further replies.

EPNICO

MIS
Jun 14, 2001
45
US
Hello Everyone:
Short question how do I copy a char array to another char array or swap elements from one array to another. I tried to use pointers but with no success.

My array's are defined as alphadata [10] [15].

Any ideas are welcomed.

Thanks.


 
Swapping elements is as simple as saying

temp = arrayONE[2][3];
arrayONE[2][3] = arrayTWO[2][3];
arrayTWO[2][3] = temp;

you can have for loops swap whole arrays if you'd like, just be careful about going out of bounds, or overwriting the terminating null character.
 
i think it's easier to swap pointers
so
you've to define two pointers
<type> *p1;
<type> *p2;
<type> *tmp;
tmp=p1;
p1=p2;
p2=tmp;

but this works with only dynamic array not with statics one that are defined like this <type> p[nbr];
mail me if don't understand anything
anass.b@t2s.co.ma
[afro]
good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top