How to express 10 milliseconds using timeval in C

2 Answers

0 votes
#include <stdio.h>

struct timeval {
   long tv_sec;    // seconds 
   long tv_usec;   // microseconds
};

int main() {
    struct timeval tv;
    
    tv.tv_sec = 0;
    // tv_usec represented as the number of microseconds 
    // 1 microseconds = 0.001 milliseconds
    // 10000 microseconds = 10 milliseconds
    tv.tv_usec = 10000; 

    return 0;
}




/*
run:



*/

 



answered Jan 20, 2024 by avibootz
0 votes
#include <stdio.h>
#include <sys/time.h> 

int main() {
    struct timeval tv;
    
    tv.tv_sec = 0;
    // tv_usec represented as the number of microseconds 
    // 1 microseconds = 0.001 milliseconds
    // 10000 microseconds = 10 milliseconds
    tv.tv_usec = 10000; 

    return 0;
}




/*
run:



*/

 



answered Jan 20, 2024 by avibootz
...