#How to run to files asynchronously in c?

19 messages · Page 1 of 1 (latest)

frail cypress
fading saddleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

ocean epoch
#

what?

#

That's a C++ source file name.

frail cypress
#

no no the link has cpp at last. Please visit the link its c source code.

#

#include <stdio.h>
#include <time.h>
#include <windows.h>
void gotoxy(int x, int y)
{
COORD c; ///COORD is a structure to hold screen COORDinates X and Y.
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c); //1. HANDLE 2. COORD
}
void c_time()
{
while(1){
time_t s = time(NULL);
struct tm* cur_time;
cur_time= localtime(&s);
gotoxy(5, 5);
printf("Time: %02d:%02d:%02d", cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec);
}
}
int main(){
c_time();
printf("Here");

return 0;

}

fading saddleBOT
#

```cpp
int main() {
return 0;
}
```

ocean epoch
#

That busy loop you have there will eat 100% of a CPU core's cycles (or at least try very hard)

#

It'll print the time thousands of times per second

frail cypress
#

yeah! Is there any better way to do that using c?

ocean epoch
#

Use clock_nanosleep()

#

as for the printf, you could try

#
int main(void) {
    gotoxy(5, 6);
    printf("Here");
    c_time();
    return 0;
}```
#

(assuming those coordinates are absolute)

frail cypress
#

yeah, but the problem is I need to do more stuff after c_time() function called.

ocean epoch
#

then you need a main loop that prints the time, does stuff, sleeps, prints the time, does stuff, sleeps...

#

it depends on what you need to do

frail cypress
#

ok, I got it.

#

!solved