A function is sometimes useful sometimes not much is the delay (), used to make a pause 'n' seconds.In some Borland compilers this function is included in the conio.h library but here are the free software side we will do ourselves this function. First let's see how it is used:
ie:
or
ie:
And of course, the function is this:
delay(variable_tipo_int);
ie:
int secs=10;
delay(secs);
or
delay(numero_entero);
ie:
delay(12);
And of course, the function is this:
void delay(int secs) {
for(int i = (time(NULL) + secs); time(NULL) != i; time(NULL));
}
- The function time (NULL) returns us to the exact second we are.
- If we add a certain amount of seconds we get a date in the future.
- At each turn of the cycle checks if the date in the future is different from the current date.
- As the two dates are equal, the cycle ends and the program continues.
Let's see how it is used in a program in c + +:
To use the delay function in this way is necessary to put in all programs where we need to use it (now I realize I have not written much about functions) and always include the library # include <time.h> or# include <ctime >.
0 comments:
Post a Comment