More C Programs By Sharjeel
Working With Time in C
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"TIME_IS:::: %d.",timeinfo);
puts (buffer);
return 0;
}
/*
(SPECIFIER) REPLACED BY) (EXAMPLE)
%a Abbreviated weekday name Thu
%A Full weekday name Thursday
%b Abbreviated month name Aug
%B Full month name August
%c Date and time representation Thu Aug 23 14:55:02 2001
%d Day of the month(01-31) 23
%H Hour in 24h format (00-23) 14
%I Hour in 12h format (01-12) 02
%j Day of the year (001-366) 235
%m Month as a decimal number (01-12) 08
%M Minute (00-59) 55
%p AM or PM designation PM
%S Second (00-61) 02
%U Week number with the first Sunday as the first day of week one (00-53) 33
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
%W Week number with the first Monday as the first day of week one (00-53) 34
%x Date representation 08/23/01
%X Time representation 14:55:02
%y Year, last two digits (00-99) 01
%Y Year 2001
%Z Timezone name or abbreviation CDT
%% A % sign %
*/
====================================================================================
/* This program shows how to pick up the scan codes from a keyboard */
/* These define the scan codes(IBM) for the keys. All numbers are in decimal.*/
#define PAGE_UP 73
#define HOME 71
#define END 79
#define PAGE_DOWN 81
#define UP_ARROW 72
#define LEFT_ARROW 75
#define DOWN_ARROW 80
#define RIGHT_ARROW 77
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
char KeyStroke;
cout << "Press Escape to quit." << endl;
do
{
KeyStroke = getch();
if (KeyStroke == 0)
{
KeyStroke = getch(); // Even though there are 2 getch() it reads one keystroke
switch (KeyStroke)
{
case PAGE_UP:
cout << "PAGE UP" << endl;
break;
case PAGE_DOWN:
cout << "PAGE DOWN" << endl;
break;
case HOME:
cout << "HOME" << endl;
break;
case END:
cout << "END" << endl;
break;
case UP_ARROW:
cout << "UP ARROW" << endl;
break;
case DOWN_ARROW:
cout << "DOWN ARROW" << endl;
break;
case LEFT_ARROW:
cout << "LEFT_ARROW" << endl;
break;
case RIGHT_ARROW:
cout << "RIGHT_ARROW" << endl;
break;
case F1:
cout << "F1" << endl;
break;
case F2:
cout << "F2" << endl;
break;
case F3:
cout << "F3" << endl;
break;
case F4:
cout << "F4" << endl;
break;
case F5:
cout << "F5" << endl;
break;
case F6:
cout << "F6" << endl;
break;
case F7:
cout << "F7" << endl;
break;
case F8:
cout << "F8" << endl;
break;
case F9:
cout << "F9" << endl;
break;
case F10:
cout << "F10" << endl;
break;
default:
cout << "Some other key." << endl;
}
}
else
cout << KeyStroke << endl;
}
while (KeyStroke != 27); // 27 = Escape key
}