473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

millitime

cdg
Could anyone tell me how to correctly write this, so that the milliseconds
are printable in "main".

#include <sys/timeb.h>
#include <iostream.h>

int GetMilliTime();

void main( )
{
int tm(0);
GetMilliTime( );
cout << tm << endl;
}

int GetMilliTime( )
{
struct _timeb tstruct;
_ftime( &tstruct );
int tm = tstruct.millitm;

return tm;
}
Feb 20 '06 #1
3 7111
"cdg" wrote:
Could anyone tell me how to correctly write this, so that the
milliseconds
are printable in "main".

#include <sys/timeb.h>
#include <iostream.h>

int GetMilliTime();

void main( )
{
int tm(0);
GetMilliTime( );
cout << tm << endl;
}

int GetMilliTime( )
{
struct _timeb tstruct;
_ftime( &tstruct );
int tm = tstruct.millitm;

return tm;
}


Try this:
#include <sys/timeb.h>
#include <iostream.h>

int GetMilliTime();

int main( )
{
//int tm(0);

you do nothing to change tm.

cout << GetMilliTime( ) << endl;
//int x = 0;
double x = 0.0;
for(long i=0; i<34000000; i++)
x*x*x*x*x*x*x;
cout << GetMilliTime() << endl;

//system("pause");
}

int GetMilliTime( )
{
struct _timeb tstruct;
_ftime( &tstruct );
int tm = tstruct.millitm;
return tm;
}

Feb 20 '06 #2
cdg
I was just wanting to know how to make another function for the routine
already written.
This is the program written in "main". And it works exactly as I need it.
But I would like to put it into another function and call it from "main".
So, I am not sure how to pass the referenced struct variable, or how it is
exactly written. And it is just the milliseconds from the clock.
This code has been copied from the "time-t" documentation in C++ 6.
Everything else has been removed except the milli-seconds.

#include <sys/timeb.h>
#include <iostream.h>

void main()
{
struct _timeb tstruct;
_ftime( &tstruct );
cout<<tstruct.millitm<<endl;
}
Feb 20 '06 #3
cdg
If anyone is interested, I figured out this way to correctly write my
previous posted code. However, I am not sure what "#include" file is needed
when using "namespace std;".
If anyone knows what this header file is using "namespace std;" and
getting the milliseconds. Would you post it.

#include <sys/timeb.h>
#include <iostream.h>

unsigned short GetMilliTime(unsigned short *);

int main()
{
unsigned short mltm;
GetMilliTime(&mltm);
cout<<mltm<<endl;
return 0;
}

unsigned short GetMilliTime(unsigned short *mltm)
{
struct _timeb tstruct;
_ftime( &tstruct );
*mltm = tstruct.millitm;
return *mltm;
}

-----------------------------------------------

"cdg" <an****@anywhere.com> wrote in message
news:iGdKf.184919$oG.106006@dukeread02...
Could anyone tell me how to correctly write this, so that the milliseconds are printable in "main".

#include <sys/timeb.h>
#include <iostream.h>

int GetMilliTime();

void main( )
{
int tm(0);
GetMilliTime( );
cout << tm << endl;
}

int GetMilliTime( )
{
struct _timeb tstruct;
_ftime( &tstruct );
int tm = tstruct.millitm;

return tm;
}

Feb 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.