Iv'e written a function to save some strings and floats (function parameters to be loaded later) to simple ASCII file. The variables are written to the file, based on data in an array, accessed with a for loop.
To write the strings, i'm using strncpy to copy the values into temporary variables, so I can keep everything at a consistant size.
However, when it saves, it saves so that the the string variables don't seem to change..tmptex0 writes the same thing over and over.

GLUI_String is a type, so it has to use sizeof() (same as you would use sizeof(float) or sizeof(int)).

-psychopath

09-13-2005

swoopy

1) How are tmptex0 and tmptex0 declared?
2) What happens if you print prefabP[i].strtexture0, prefabP[i].strtexture1, meshP[i].tex1, and meshP[i].tex2 directly instead of copying them to a temporary first?

Also, you may want to print sizeof(GLUI_String) is to be sure it's what you expect.

These strings are taken in from text-boxs that write to strings that HAVE to be >=GLUI_String. The strncpy makes sure that all the file name strings being read and written are >=GLUI_String.
(^not sure if thats explained clearly enough, but thats the best I can do^)

-psychopath

09-14-2005

Ancient Dragon

how is GLUI_String declared? using sizeof operator on it may or may not work.

Well, assuming prefabP[i].strtexture0, prefabP[i].strtexture1, meshP[i].tex1, and meshP[i].tex2 are all char arrays, that pretty much indicates the problem is elsewhere, if each array element is printing out the same string.

09-16-2005

psychopath

Those variables arn't arrays..so what does that mean?:

Code:

char *strtexture0;
char *strtexture1;

Code:

char *filename;
char *tex1;
char *tex2;

-psychopath

09-17-2005

swoopy

>Those variables arn't arrays..so what does that mean?:
Well those are just pointers to char, so unless you allocate some memory for them, you can't copy char strings into them, you can only assign other char pointers to them.

So if you're trying to store strings in them, you need to use new to allocate some memory for them, or make them strings or char arrays.