3

I am trying to use rand,srand and time to generate random(enough) numbers in C.I use DEVC++.I get the following error: [Linked Error]undefined reference to 'gettimeofday' error

Here is my code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>

static unsigned long next = 1;

    int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}

void mysrand(unsigned seed) {
next = seed;
}

struct  {
   long tv_sec;
   long tv_usec;
       }timeval ;

int main(){


int num=0;               //random number

struct timeval t1;  


gettimeofday(&t1, NULL);
srand(t1.tv_usec * t1.tv_sec);

arg_num=rand();

printf("Number of arguments is:%d\n",arg_num);

}

Making an online research i found out that DEVC++ (somehow) includes GNU compiler but it doesn't really use it and that results in not identifying all "common" functions. Beyond solving the linked error, i would like to know if there is an IDE for C programming in Windows that uses GNU or that will not making such problems..

Dchris
  • 2,867
  • 10
  • 42
  • 73
  • For the latter you might like to go for Cygwin. – alk Dec 16 '12 at 09:53
  • There is no `gettimeofday()` provided by windows. Do build our own you might like to carve here: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/430449b3-f6dd-4e18-84de-eebd26a8d668/ – alk Dec 16 '12 at 09:58
  • from Cygwin website:Cygwin is: a collection of tools which provide a Linux look and feel environment for Windows.Cygwin is not: a way to run native Linux apps on Windows. – Dchris Dec 16 '12 at 15:54
  • 1
    You use Ecplise for Window and the Cygwin based GNU tool chain. This enables you to use build Windows binaries from GNU based sources. – alk Dec 16 '12 at 16:10

1 Answers1

0

There is no gettimeofday() provided by Windows.

Dchris
  • 2,867
  • 10
  • 42
  • 73