I don’t know how I can create threads in C, I saw a review about the pthread.h library, but then I heard that it is only for Linux OS, I have a function in which there is a timer, I want to create a thread with this function , but I don’t know either the library that I need to use, or the syntax for writing code, if someone could provide me with simple code with threads or say what things I need to put and the function parameter.
Here its function I creates a countdown of the time during which the user applies: I need to create a stream with this function.
Function (countdown):
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void countdown(int second)
{
int secs = 1;
time_t unix;
struct tm * timeinfo;
time(&unix);
timeinfo = localtime(&unix);
int t1 = timeinfo->tm_sec;
int t2 = timeinfo->tm_sec;
int i = 0;
while(1 == 1)
{
time(&unix);
timeinfo = localtime(&unix);
if((t1 + i) == timeinfo->tm_sec)
{
system("cls");
printf("Time left %d\n", timeinfo->tm_sec - t2 - second);
i++;
}
if(timeinfo->tm_sec >= (t1 + second))
{
system("cls");
puts("Your time its done");
break;
}
}
}
int main()
{
int limit;
printf("How much time would you like (In secs): ");
scanf("%d", &limit);
countdown(limit);
system("PAUSE");
return 0;
}
source
share