C Programming Code Examples
C > Hardware Interaction Through C Code Examples
Program for Scrolling the Window Down
/* Program for Scrolling the Window Down */
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main(void)
{
clrscr();
union REGS regs;
regs.h.ah = 07;
regs.h.al = 5;
regs.h.bh = 8;
regs.h.ch = 0;
regs.h.cl = 0;
regs.h.dh = 50;
regs.h.dl = 50;
int86(0x10,®s,®s);
getch();
}
A union is a special data type available in C that allows to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose. To define a union, you must use the union statement in the same way as you did while defining a structure. The union statement defines a new data type with more than one member for your program. The format of the union statement is as follows:
Function clrscr() clears the screen and moves the cursor to the upper left-hand corner of the screen. If you are using the GCC compiler, use system function to execute the clear/cls command. clrscr() function is also a non-standard function defined in "conio.h" header. This function is used to clear the console screen. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.
#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:
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.
The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program.
C program to read elements in a matrix and perform scalar multiplication of matrix. C program for scalar multiplication of matrix. How to perform scalar matrix multiplication
First give a meaningful name to the recursive function to print even odd numbers. Let's say printEvenOdd(). This function can print both even as well as Odd Numbers in given range.
Create a structure. The name of the structure is StudentData. The Student is the variable of structure StudentData. Assigning the values of each struct member here. Displaying the...
This Code is very simple and a good example of using conditional statement (if-else) in an iteration (i.e. for loop). We shall initiate a for loop having some finite iterations and check
C program to remove all Repeated characters in a String using loops. Input string from user. Remove all duplicate characters from a given string. Remove all occurrences of a character