You are here:

C++/c program

Advertisement


Question
I am attempting to make a program print time to my video overlay screen, but it needs to put in as a string.
the program I'm attempting to modify has the out put as a printf statement with the following code.


iRCode = bcReadBinTime(
&tmmaj, // major time - binary time in seconds
&tmmin,    // minor time in useconds
&tmstat      // status of the board, tracking
);

     
if ( iRCode == RC_OK ){

majtime = gmtime( &tmmaj );


printf("\nTime: %02d/%02d/%d  %02d:%02d:%02d.%06lu",majtime->tm_mon+1, majtime->tm_mday, majtime->tm_year+1900,majtime->tm_hour, majtime->tm_min, majtime->tm_sec, tmmin);


I tried to use the ctime function but I can't get the milliseconds to show up.  If you could let me know how to get the above into a string so I can out put it, or show me how to print milliseconds with ctime, it would help me out a great deal.

thanks in advance
P.S.
the way I've been getting things to print with the overlay is as follows:

char *s=ctime(&tmmaj);
strcpy(OutString,s);
WriteFile(hCom,OutString,strlen(OutString),&BytesWritten,NULL);


Answer
Hi there:
 I hope u'll be fine. The actual thing in the printf function is
majtime->tm_mon+1, majtime->tm_mday, majtime->tm_year+1900,majtime->tm_hour, majtime->tm_min, majtime->tm_sec, tmmin

U need to convert all these seperatly to strings and then concatenate all those strings.

To convert an int to a string u can use the itoa function and there are similar functions available for converting float to strings. So get the above values converted to strings by using these functions.
After that use the strcpy and strcat functions to combine all those values in a single string and u r done.

Plz. feel free to ask a followup, if u need to.
Thanks for contacting me
Zaigham

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


zaigham

Expertise

I can answer any questions that range from the very basics of c++ to the advanced topics like polymorphism, inheritance, composition, multiple inheritance and templates. I can also answer almost every type of questions about c++ data structures like stack, queue, circular queue, linklist(single, double, circular), binary trees, binary search trees, avl trees, 2-3 and 2-3-4 trees. I dont have much experience of mfc and creating guis in visual c++, so plz. dont ask me questions about that.

Experience

I'm working in c++ since the last 6 years. I've good working skills specially in the advanced topics like inheritance, polymorphism and all type of c++ data structures.

©2016 About.com. All rights reserved.