Advertisement

string copy problem

Started by March 13, 2003 11:10 AM
1 comment, last by Freaker13 21 years, 8 months ago
Hi all, How do i copy a string from a temporary variable to a global variable? global: char str1[25][256]; function: tempStrBuffer contains "hello" memcpy(str1,tempStrBuffer,5); ->str1 points to hello tempStrBuffer->release(); ->i lost the info in str1 How do i get those "hello" in a global variable without losing it after the release()? thx in advance [edited by - Freaker13 on March 13, 2003 12:11:13 PM]
You have: char str1[25][256];

str1 is a pointer to an array of char pointers, since you have a 2 dimensional array. If you really want to keep it as a 2D array, you should pass what row you want it to go on. Like:

memcpy(str1[1],tempStrBuffer,6);
Advertisement
thats what i have (type error)
But the tempStrBuffer is a local variable in a for-loop. When i go out of this loop,str1 changes.

global:
char texturePaths[25][256];



for(i=0; inumMaterials; i++)
{
memcpy(texturePaths,materials.pTextureFilename,5);<br>}<br> ->when i come here,texturePaths changes<br>i think because materials is a local variable in the loop and it's deleted after ending the loop.so texturePaths points to nothing. But how can i solve this?<br><br><br> </i> <br><br><SPAN CLASS=editedby>[edited by - Freaker13 &#111;n March 13, 2003 12:44:18 PM]</SPAN>

This topic is closed to new replies.

Advertisement