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

help on poinetrs

Status
Not open for further replies.

sreeram

Programmer
Joined
Apr 3, 2000
Messages
1
Location
US
hi can any one say if i can copy one pointer to another with a string added to the second pointer before copying.i did try using stringcopy but i couldn't get result.so can anyoine help me
 
I didn't get your question properly . If you want to copy two strings of pointers . Here is a single line code:<br><br>while(*dest++ = *source++);<br><br>Does it answer your question ?<br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
If i interpret your question correctly you have<br>one pointer such as<br>char * test1 = &quot;whatever&quot;<br>then have a string<br>say<br>char [] test2 = &quot;example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;;<br>You can then copy the characters from test1 to test2<br>bye putting it in a loop like<br><br>for (int i = 8; i &lt;= 18; i++)<br> test2<i> = *(test1++);<br><br>this copies the characters from one to another, just <br>becarefull not to copy the memory address of the pointer<br>and that you actually have the additional room in the <br>string.&nbsp;&nbsp;oh all the statements might no be exact it has been awile since i did c :)<br><br>hope this helps&nbsp;&nbsp;ackka <p>moses<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= </a><br>
 
My problem is i am using two pointers in a function which is called in main , so as and when i come out of the fucntion i have to get all the contants of the pointer cleared so that when i call the function again i get as if i am using a new pointer else when i am call the fuction again the arguments r getting added to the pointer.like<br><br>main(){<br>char *des1<br>char *scr1<br>char *name1;<br>char *value1;<br><br>&nbsp;fun_text(des1,scr1,name,value);<br>}<br><br>void fun_text(char *des,char *scr,char *name,char *value)<br>{<br><br>coding for function...<br>}<br><br><br>here in the above for the first time my fuction is working fine but when i call it second time its giving me problem,the arguments i am passing r getting added to the previous pointer only.<br><br>sugget a way where in i can clear the contents of pointer in function<br>
 
O.k , You do one thing . When you are going to call the function next time. Just do<br>src = NULL;<br>dest = NULL;<br>But one question are you allocating memory to the pointers any where or not ?<br>If not then behaviour would be different.<br><br>Does this answer your question ?<br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top