_delay_ms( ) function accepts only a constant in milliseconds as parameter, write a function void delay(int a) that produces a delay where “a” is a variable in C
i'm writing a function to produce a milliseconds of delay, you can run this code on any c ide:
#include <stdio.h>
#include <time.h>
void delay(int a){//a is number of seconds
int mls = 1000*a; //convert to milliseconds...if you want a to be in milliseconds just comment this line
clock_t f = clock();
while(clock()< f+mls){}// do nothing i.e. create delay
}
void main()
{
int i;
for (i= 1; i <= 10; i++) {
delay(1);
printf("%d second\n", i );
}
}
Get Answers For Free
Most questions answered within 1 hours.