Pelles C forum
C language => Beginner questions => Topic started by: sp1541 on January 12, 2011, 05:41:02 PM
-
Hi there!
I want to compile a simple program which was written for unix in windows.
In Pelles C 6.50.4 RC3 the instruction _gettimeofday() is implemented.
I need "#include <sys/time.h>" to use that and the structs timeval and timezone.
This file does not exist. I tried to use "timeb.h" or copy it from gcc.
In the end I only need a solution to get a precise time on windows.
Any ideas?
Sorry for my english...
-
Try it with just #include <time.h>
In PellesC the time.h file is in the include directory on your search path.
If you installed on defaults, look in the c:\program files\pellesc\include folder.
-
For PellesC 6.5 only.
#include <stdio.h>
//#include <sys/time.h>
typedef struct timeval {
long tv_sec;
long tv_usec;
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
int main(int argc, char **argv)
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
gettimeofday(&tv, NULL);
if (tv.tv_sec)
printf("%d\n", (long)tv.tv_sec);
return 0;
}
You can test sys/time.h like this
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
typedef struct timeval {
long tv_sec;
long tv_usec;
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
#endif /* _SYS_TIME_H */
This is not used.
typedef struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
-
thank you!
@CommonTater:
time.h was already included
@timovjl:
Your solution will work with my code, I think.
I got only an error because struct timezone isn't defined but I think I will find how to define it.