Osaisiko joku neuvoa miten tehdään c :ssalla lyhyt ohjelma joka ajastaa
5sec --> teksti 1
4sec --> teksti 2
3sec --> teksti 3
2sec --> teksti 4
1sec --> teksti 5
0sec --> exit
5sec --> teksti 1
4sec --> teksti 2
3sec --> teksti 3
2sec --> teksti 4
1sec --> teksti 5
0sec --> exit
Vastaukset 4
Vanhimmat
Tästäpä lähtökohta
#include
#include stdio.h
#include time.h
#include conio.h
int main( )
{
char dateStr [9];
char timeStr [9];
_strdate( dateStr);
printf( "The current date is %s \n", dateStr);
_strtime( timeStr );
printf( "The current time is %s \n", timeStr);
getche();
return 0;
}
Tällainen on myös nahdollinen
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
#include Windows.h
#include stdio.h
#include conio.h
int main(void)
{
SYSTEMTIME st;
GetSystemTime(&st);
int start_second=st.wSecond;
printf("%d", start_second);
//printf("Year:%d\nMonth:%d\nDate:%d\nHour:%d\nMin:%d\nSecond:% d\n" ,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
while(1)
{
GetSystemTime(&st);
int present_second=st.wSecond;
if(present_second==start_second+3)
{
printf("One mennyt kolme sekuntia. ");
}
}
getche();
return 0;
}