C
cdg
Could anyone tell me why a function return with this program is not
returning to "main". The program will compile and should be
self-explanatory. And any suggestions for improvements would be appreciated
also.
The function is HashMilliTime at the end of the program.
#include <sys/timeb.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
unsigned short GetMilliTime(unsigned short *); //function prototype
unsigned HashMilliTime (char[], int); //function prototype
void main()
{
unsigned short mltm(0); //milli-seconds for time
char mltmch[5] = {0}; //milli-seconds as character array
int mltmln(0); //length of milli-seconds as character array
// unsigned h(0); //hashed milli-seconds
GetMilliTime(&mltm);
cout<<mltm<<endl; //test only remove later
itoa( mltm, mltmch, 10 );
cout<<mltmch<<" char"<<endl; //test only remove later
mltmln = strlen(mltmch);
cout<<mltmln<<endl; //test only remove later
cout<<mltmch<<" before"<<endl; //test only remove later
HashMilliTime(mltmch, mltmln);
//**The returned unsigned int will not print here**
cout<<mltmch<<" should be same as h"<<endl; //test only remove later
cout<<mltmln<<endl; //test only remove later
}
unsigned short GetMilliTime(unsigned short *mltm)
{
struct _timeb tstruct;
_ftime( &tstruct );
*mltm = tstruct.millitm;
return *mltm;
}
unsigned HashMilliTime (char key[], int len )
{
char *p = key;
unsigned h = 0;
int i(0);
unsigned x(0);
for ( i = 0; i < len; i++ )
{
h += p;
h += ( h << 10 );
h ^= ( h >> 6 );
}
h += ( h << 3 );
h ^= ( h >> 11 );
h += ( h << 15 );
cout<<len<<" hash"<<endl; //test only remove later
cout<<h<<" hash"<<endl; //test only remove later
return h;
x = len + 5; //test only remove later
return x; //test only remove later
}
returning to "main". The program will compile and should be
self-explanatory. And any suggestions for improvements would be appreciated
also.
The function is HashMilliTime at the end of the program.
#include <sys/timeb.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
unsigned short GetMilliTime(unsigned short *); //function prototype
unsigned HashMilliTime (char[], int); //function prototype
void main()
{
unsigned short mltm(0); //milli-seconds for time
char mltmch[5] = {0}; //milli-seconds as character array
int mltmln(0); //length of milli-seconds as character array
// unsigned h(0); //hashed milli-seconds
GetMilliTime(&mltm);
cout<<mltm<<endl; //test only remove later
itoa( mltm, mltmch, 10 );
cout<<mltmch<<" char"<<endl; //test only remove later
mltmln = strlen(mltmch);
cout<<mltmln<<endl; //test only remove later
cout<<mltmch<<" before"<<endl; //test only remove later
HashMilliTime(mltmch, mltmln);
//**The returned unsigned int will not print here**
cout<<mltmch<<" should be same as h"<<endl; //test only remove later
cout<<mltmln<<endl; //test only remove later
}
unsigned short GetMilliTime(unsigned short *mltm)
{
struct _timeb tstruct;
_ftime( &tstruct );
*mltm = tstruct.millitm;
return *mltm;
}
unsigned HashMilliTime (char key[], int len )
{
char *p = key;
unsigned h = 0;
int i(0);
unsigned x(0);
for ( i = 0; i < len; i++ )
{
h += p;
h += ( h << 10 );
h ^= ( h >> 6 );
}
h += ( h << 3 );
h ^= ( h >> 11 );
h += ( h << 15 );
cout<<len<<" hash"<<endl; //test only remove later
cout<<h<<" hash"<<endl; //test only remove later
return h;
x = len + 5; //test only remove later
return x; //test only remove later
}