CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2002
    Posts
    8

    Unhappy how to convert type clock_t value to char

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

  2. #2
    Join Date
    Jun 2002
    Posts
    1,417

    Re: how to convert type clock_t value to char

    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?

  3. #3
    Join Date
    Jul 2002
    Posts
    8

    Unhappy

    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.

  4. #4
    Join Date
    Jun 2002
    Posts
    1,417
    If all you want to do is display the value of it, one way to convert it to char * is to use sprintf() function:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured