C language implements precise latency and achieves similar sleep functions

Updated on technology 2024-05-26
7 answers
  1. Anonymous users2024-02-11

    This one can. #include

    #include

    main()

    void sleep(long wait);

    int n;

    printf("Enter the number of delay seconds:")

    scanf("%d",&n);

    sleep(n*1000);

    printf("hello!");

    return 0;

    void sleep(long wait)long goal=clock()+wait;

    while(goal>clock())

    Send a timer to you to see the accuracy of no, copy the following ** to see it, please enter the exact time format when you watch: minutes: seconds.

    If it's 12:00 now, you can enter 12:1:00 to test.

    #include

    #include

    #include

    main()

    void sleep(long wait);

    int h,m,s,sum;

    char n[128];

    time_t timer;

    printf("Enter the exact time format (hour:minute:second) t");

    scanf("%d:%d:%d",&h,&m,&s);

    time(&timer);

    tm* t=localtime(&timer);

    sum=((h-(t->tm_hour))*3600+(m-(t->tm_min))*60+s-(t->tm_sec));

    for(int i=sum,j=59;i>=1;i--,j--)system("cls");

    strtime(n);

    printf("%s",n);

    for(int k=1;k<=j;k++)printf(" ");

    printf("this is a c program!");

    sleep(1000);

    system("cls");

    strtime(n);

    printf("%s",n);

    printf("game over!");

    return 0;

    void sleep(long wait)long goal=clock()+wait;

    while(goal>clock())

  2. Anonymous users2024-02-10

    Use nop (), it's very precise.

    Header file: include

    Statement: nop() is equivalent to the assembled nop

    This means that an empty instruction is delayed by 1 instruction cycle. Each nop () is equivalent to 2us.

    For example, it takes 10us:

    nop_()

    nop_()

    nop_()

    nop_()

    nop_()

    This is basically the same as using the assembly directly, which is very precise.

  3. Anonymous users2024-02-09

    There is no sleep function in the C standard library, it is actually a system API function.

    Function function: Execution is suspended for a period of time.

    1. Use the header file in VC, and the full name is sleep(), and the first letter needs to be capitalized.

    include header file needs to be added.

    sleep(unisgned long);The function declares that the unit in sleep() in windows is measured in milliseconds, so if you want the function to stay for 1 second, it should be written:

    sleep(1000);

    2. In GCC, the header files used vary depending on the GCC version, generally speaking, the header files that need to be added to the Linux system are:

    #include

    should be sleep(1000);

    Under Linux, sleep() is measured in seconds, not milliseconds.

  4. Anonymous users2024-02-08

    You're not calling the same function, are you? sleep and sleep are two different functions. Generally, the sleep parameter is milliseconds, so 1000 is equal to 1 second.

    But in the early days of Turbo C Borland C there was a sleep function in seconds. It seems to include ?

  5. Anonymous users2024-02-07

    This thing marker, just like the variable name, what do you think of, the name can be, you know the rules of the name, the mark that starts with a letter or an underscore, sleep is a keyword, use an underscore to distinguish, generally the function name that starts with an underscore is a library function, this is an unspoken rule, the C standard does not have requirements in this regard!

  6. Anonymous users2024-02-06

    Custom function sleep:void sleep(int n)--

    Example of a program: include

    #include

    #include

    void sleep(int n)

    int main()

  7. Anonymous users2024-02-05

    sleep has always been counted in seconds, right· js is calculated in milliseconds.

Related questions
12 answers2024-05-26

Python is a cross-platform computer programming language. It is an object-oriented, dynamically typed language that was originally designed to write automation scripts (shells) and is increasingly being used for the development of independent, large-scale projects as versions are updated and new features of the language are added. >>>More

3 answers2024-05-26

I guess I can only write like this upstairs. However, there is still a big gap between this writing and the standard text input function of the console (such as scanf), such as not being able to use the arrow keys, not being able to use home end, etc. Of course, you can add these features yourself, but it's always hard to do it all, since the standard functions of other consoles have been improved over generations. >>>More

8 answers2024-05-26

I want to ask, have you written it now?

6 answers2024-05-26

The algorithm is as follows: 1. Take a row from gridview1 and store it in datarow. >>>More