I simply did not consider searching for important information about it.
When I look about it now I see that at least for time I can find the following example in the help file
I guess that it is least ok if I copy something from examples like that
because without copying from some source I have no chance to do things
but I also think that if everybody has to invent the same wheel of measuring time and checking for input the progress in computer chess is going to be slower because people may need significant time to do it
Code: Select all
// crt_times.c
// compile with: /W1
// This program demonstrates these time and date functions:
// time _ftime ctime_s asctime_s
// _localtime64_s _gmtime64_s mktime _tzset
// _strtime_s _strdate_s strftime
//
// Also the global variable:
// _tzname
//
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>
int main()
{
char tmpbuf[128], timebuf[26], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm today, gmt, xmas = { 0, 0, 12, 25, 11, 93 };
errno_t err;
// Set time zone from TZ environment variable. If TZ is not set,
// the operating system is queried to obtain the default value
// for the variable.
//
_tzset();
// Display operating system-style date and time.
_strtime_s( tmpbuf, 128 );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );
// Get UNIX-style time and display as number and string.
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
err = ctime_s(timebuf, 26, <ime);
if (err)
{
printf("ctime_s failed due to an invalid argument.");
exit(1);
}
printf( "UNIX time and date:\t\t\t%s", timebuf );
// Display UTC.
err = _gmtime64_s( &gmt, <ime );
if (err)
{
printf("_gmtime64_s failed due to an invalid argument.");
}
err = asctime_s(timebuf, 26, &gmt);
if (err)
{
printf("asctime_s failed due to an invalid argument.");
exit(1);
}
printf( "Coordinated universal time:\t\t%s", timebuf );
// Convert to time structure and adjust for PM if necessary.
err = _localtime64_s( &today, <ime );
if (err)
{
printf("_localtime64_s failed due to an invalid argument.");
exit(1);
}
if( today.tm_hour >= 12 )
{
strcpy_s( ampm, sizeof(ampm), "PM" );
today.tm_hour -= 12;
}
if( today.tm_hour == 0 ) // Adjust if midnight hour.
today.tm_hour = 12;
// Convert today into an ASCII string
err = asctime_s(timebuf, 26, &today);
if (err)
{
printf("asctime_s failed due to an invalid argument.");
exit(1);
}
// Note how pointer addition is used to skip the first 11
// characters and printf is used to trim off terminating
// characters.
//
printf( "12-hour time:\t\t\t\t%.8s %s\n",
timebuf + 11, ampm );
// Print additional time information.
_ftime( &tstruct ); // C4996
// Note: _ftime is deprecated; consider using _ftime_s instead
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in hours from UTC:\t%u\n",
tstruct.timezone/60 );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); //C4996
// Note: _tzname is deprecated; consider using _get_tzname
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );
// Make time for noon on Christmas, 1993.
if( mktime( &xmas ) != (time_t)-1 )
{
err = asctime_s(timebuf, 26, &xmas);
if (err)
{
printf("asctime_s failed due to an invalid argument.");
exit(1);
}
printf( "Christmas\t\t\t\t%s\n", timebuf );
}
// Use time structure to build a customized time string.
err = _localtime64_s( &today, <ime );
if (err)
{
printf(" _localtime64_s failed due to invalid arguments.");
exit(1);
}
// Use strftime to build a customized time string.
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", &today );
printf( tmpbuf );
}
Code: Select all
// crt_spawn.c
// This program accepts a number in the range
// 1-8 from the command line. Based on the number it receives,
// it executes one of the eight different procedures that
// spawn the process named child. For some of these procedures,
// the CHILD.EXE file must be in the same directory; for
// others, it only has to be in the same path.
//
#include <stdio.h>
#include <process.h>
char *my_env[] =
{
"THIS=environment will be",
"PASSED=to child.exe by the",
"_SPAWNLE=and",
"_SPAWNLPE=and",
"_SPAWNVE=and",
"_SPAWNVPE=functions",
NULL
};
int main( int argc, char *argv[] )
{
char *args[4];
// Set up parameters to be sent:
args[0] = "child";
args[1] = "spawn??";
args[2] = "two";
args[3] = NULL;
if (argc <= 2)
{
printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );
exit( 1 );
}
switch (argv[1][0]) // Based on first letter of argument
{
case '1':
_spawnl( _P_WAIT, argv[2], argv[2], "_spawnl", "two", NULL );
break;
case '2':
_spawnle( _P_WAIT, argv[2], argv[2], "_spawnle", "two",
NULL, my_env );
break;
case '3':
_spawnlp( _P_WAIT, argv[2], argv[2], "_spawnlp", "two", NULL );
break;
case '4':
_spawnlpe( _P_WAIT, argv[2], argv[2], "_spawnlpe", "two",
NULL, my_env );
break;
case '5':
_spawnv( _P_OVERLAY, argv[2], args );
break;
case '6':
_spawnve( _P_OVERLAY, argv[2], args, my_env );
break;
case '7':
_spawnvp( _P_OVERLAY, argv[2], args );
break;
case '8':
_spawnvpe( _P_OVERLAY, argv[2], args, my_env );
break;
default:
printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );
exit( 1 );
}
printf( "from SPAWN!\n" );
}