string copy problem
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]
March 13, 2003 11:24 AM
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);
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);
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 on March 13, 2003 12:44:18 PM]</SPAN>
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 on March 13, 2003 12:44:18 PM]</SPAN>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement