LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with TimeStr

Solved!
Go to solution

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 

0 Kudos
Message 1 of 4
(3,511 Views)
Solution
Accepted by topic author Florian H.

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.  😉

Message Edited by ebalci on 11-06-2008 06:00 PM
S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 4
(3,505 Views)

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

 

0 Kudos
Message 3 of 4
(3,486 Views)

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. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 4
(3,455 Views)