Click to See Complete Forum and Search --> : how to convert type clock_t value to char


onlyhuman23
July 31st, 2002, 02:32 AM
I am using the value clock_t in my C program, and the related function clock(). The problem is that I need to display the value of clock_t variables and I can only do it in charcter type as I am displaying it in openGL with my own custom function for displaying which only takes char type string. Please help me.
Secondly what type of a function can I use to delay execution for some time. I have tried to used sleep and delay and have added the header file DOS.H. But the compiler still doesnt recognize the calls to sleep() or delay(). My program is in c++.

stober
July 31st, 2002, 04:48 AM
Originally posted by onlyhuman23
I am using the value clock_t in my C program, and the related function clock(). The problem is that I need to display the value of clock_t variables and I can only do it in charcter type as I am displaying it in openGL with my own custom function for displaying which only takes char type string. Please help me.

localtime(time_t*) returns the string that you probably want

Secondly what type of a function can I use to delay execution for some time. I have tried to used sleep and delay and have added the header file DOS.H. But the compiler still doesnt recognize the calls to sleep() or delay(). My program is in c++.

sleep() is a unix function, and Sleep() is a Win32 API function. Neither are available to MS-DOS 16-bit programs. I don't know what delay() is. What compiler are you using?

onlyhuman23
July 31st, 2002, 09:15 PM
I am using visual c 6 compiler. The sleep function works but the problem with the clock_t type remains. As I told you clock_t is a type, which is used by the function clock() to return time in milliseconds or CLOCKS_PER_SEC. I need to display them, but I cannot use the normal display functions. The only way I can display this type is by converting it co char type, or indirectly by converting it to integer and latter converting to char.

stober
July 31st, 2002, 10:00 PM
If all you want to do is display the value of it, one way to convert it to char * is to use sprintf() function:

char buffer[126];
clock_t time = clock();
sprintf(buffer,"%d", time);
cout << buffer;