You are here:

C++/c program


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
the way I've been getting things to print with the overlay is as follows:

char *s=ctime(&tmmaj);

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


All Answers

Answers by Expert:

Ask Experts




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.


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.

©2017 All rights reserved.