11-06-2008 08:48 AM
Hello,
I am having a problem with the Funktion TimeStr(). I need a char array of Measuring-Times ( char array of different TimeStr() ), but TimeStr() overwrites every old Timer.
Example Code:
---------------------------------------
int CVICALLBACK test (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char **timeframe;
int cnt=0,i=0;
int points=4;
switch (event)
{
case EVENT_COMMIT:
timeframe = (char **)malloc(points*sizeof(char*));
for(i;i<points;i++)
{
timeframe[i]=(char*)malloc(8*sizeof(char));
}
for(cnt;cnt<points;cnt++)
{
timeframe[cnt]=TimeStr();
printf("%s\n",timeframe[cnt]);
}
break;
}
return 0;
}
---------------------------------------
After "timeframe[cnt]=TimeStr();" the array-Position cnt-1 has the same Value like the actual cnt.
I want a dynamic char array with different Measure-Times.
Hope you can help me.
Thank you,
Florian
Solved! Go to Solution.
11-06-2008 09:58 AM - edited 11-06-2008 10:00 AM
Hi Florian,
Just replace the line in the second for loop with:
strcpy (timeframe[cnt], TimeStr());
Your expression using equal sign changes where the array pointers point.
You should do a memory copy instead.
This solved the problem on my computer.
Hope this helps.
IMPORTANT NOTE: Do not forget to put a delay in the loop after printf. Otherwise you end up copying the time string within the same second. 😉
11-07-2008 01:35 AM
Hi,
thank you for your reply!
With "strcpy (timeframe[cnt], TimeStr());" instead of "timeframe[cnt]=TimeStr();", there is no problem any more.
Yes of course, this was only an example code that represents my problem. In my real programm there is a Measuring-Funcion that produces a Delay.
Thanks for helping!
Florian
11-10-2008 12:33 AM
So Florian, you can mark my last post as an "accepted solution" then? 😉
This is a good feature for the forum so remember to use it when applicable.