C Programming Code Examples
C > Miscellaneous Code Examples
A TSR CLOCK
/* A TSR CLOCK */
#include "dos.h"
void interrupt ( *prevtimer )( ) ;
void interrupt mytimer( ) ;
int running = 0 ;
unsigned long far *time = ( unsigned long far * ) 0x46C ;
char far *scr ;
char far *mode ;
main( )
{
/* peek into location 0:410h and determine video mode */
if ( ( *mode & 0x30 ) == 0x30 )
scr = ( char far * ) 0xB0000000 ;
else
scr = ( char far * ) 0xB8000000 ;
prevtimer = getvect ( 8 ) ;
setvect ( 8, mytimer ) ;
keep ( 0, 1000 ) ;
}
void interrupt mytimer( )
{
unsigned char hours, sec, min ;
if ( running == 0 )
{
running = 1;
hours = ( *time / 65520 ) ;
min = ( *time - hours * 65520 ) / 1092 ;
sec = ( *time - hours * 65520 - min * 1092 ) * 10 / 182 ;
if ( sec >= 60 )
{
sec -= 60 ;
min++ ;
if ( min == 60 )
{
min = 0 ;
hours++ ;
if ( hours == 24 )
hours = 0 ;
}
}
/* display digital clock */
writechar ( 48 + hours / 10, 0, 72, 112 ) ;
writechar ( 48 + hours % 10, 0, 73, 112 ) ;
writechar ( ':', 0, 74, 112 ) ;
writechar ( 48 + min / 10, 0, 75, 112 ) ;
writechar ( 48 + min % 10, 0, 76, 112 ) ;
writechar ( ':', 0, 77, 112 ) ;
writechar ( 48 + sec / 10, 0, 78, 112 ) ;
writechar ( 48 + sec % 10, 0, 79, 112 ) ;
running = 0 ;
}
( *prevtimer )( ) ;
}
writechar ( char ch, int row, int col, int attr )
{
*( scr + row * 160 + col * 2 ) = ch ;
*( scr + row * 160 + col * 2 + 1 ) = attr ;
}
Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language: Simple assignment operator. Assigns values from right side operands to left side operand. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand.
The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness of the condition. Here, we must notice that if and else block cannot be executed simiulteneously. Using if-else statement is always preferable since it always invokes an otherwise case with every if condition.
In C, the "main" function is treated the same as every function, it has a return type (and in some cases accepts inputs via parameters). The only difference is that the main function is "called" by the operating system when the user runs the program. Thus the main function is always the first code executed when a program starts. main() function is a user defined, body of the function is defined by the programmer or we can say main() is programmer/user implemented function, whose prototype is predefined in the compiler. Hence we can say that main() in c programming is user defined as well as predefined because it's prototype is predefined. main() is a system (compiler) declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.
#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:
getvect() reads the value of one of the MS-DOS "hard-wired" interrupt vectors. These vectors are numbered 0 to 255. The 4-byte value in each one is actually an address, which is the location of an interrupt function. The vector named in 'intr_num' is interpreted as a far pointer to some interrupt function.
setvect() sets an interrupt vector entry. MS-DOS includes a set of hard-wired interrupt vectors. They are numbered 0 - 255. The 4-byte value in each vector is actually an address, which is the location of an interrupt function. setvect() sets the value of the vector 'intr_num' to a new value, 'vector'. 'vector' is a far pointer containing the address of a new interrupt function. The address of a C routine may only be passed to 'vector' if that routine is declared to be an 'interrupt' routine. The function, setvect(), takes two arguments.
The number of characters actually printed. A negative value indicates failure. Hexadecimal output in the form. Signed decimal integers. Scientific notation. Decimal floating point.
Create opening screen and accept the level of the player's. Assign the speed to ball as per the level chosen. Draw four layer of bricks, the paddle and the ball. Memory allocation
Printing alphabets in C Programming, is little trick. If you are good at basic data types and literals then this is easy for you. Internally C represent every character using ASCII Code.
This program takes a string from the user and stored in the Variable line. The, Within the for loop, each character in the string is checked if it is an alphabet or not. If any character inside
C program code input any number from user and find total number of leading zeros of the given number. How to find total leading zeros of a given number (in binary representation)