Reputation: 123
When I write a program containing delay the compiler shows the error E:\c programms\ma.o:ma.c|| undefined reference to `delay'| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Upvotes: 1
Views: 68652
Reputation: 131
Try this function:
#include <time.h> // clock_t, clock, CLOCKS_PER_SEC
void delay(unsigned int milliseconds){
clock_t start = clock();
while((clock() - start) * 1000 / CLOCKS_PER_SEC < milliseconds);
}
Upvotes: 0
Reputation: 19
You can use your own created delay() function for delaying statements for milliseconds as passed in parameter...
Function Body is below.....
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
example program is below...
#include<stdio.h>
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
int i;
for(i=0;i<10;i++)
{
delay(1000);
printf("This is delay function\n");
}
return 0;
}
Upvotes: 2
Reputation: 19385
Try including windows.h
and use Sleep(sleep_for_x_milliseconds)
instead of delay()
– Cool Guy
Upvotes: 2