Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

C > Code Snippets Code Examples

Absread in C

/* Absread in C This reads individual disk sectors , compiled with Turbo C */ #include <stdio.h> #include <dos.h> #include <stdlib.h> #include <bios.h> int main(void) { unsigned char buffer[512]; clrscr(); printf("Insert disk in the A: drive , then press any key.\n"); /*wait for keypress*/ getch(); if(absread(0,1,1,&buffer) != 0) printf("Cannot read the A drive.\n"); else printf("Drive A , Sector 1 read\n"); return 0; }

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. printf format string refers to a control parameter used by a class of functions in the input/output libraries of C programming language. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data (such as a number) to characters. "printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (parsing). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible template engines or parsers,

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 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.

The absread() function reads absolute disk sectors. The Function has been defined in Dos.h. The function absread uses DOS interrupt 0x25 to read specific disk sectors. absread() reads specific disk sectors. It ignores the logical structure of a disk and pays no attention to files , FATs, or directories. If successful, 0 is returned. -1 is returned on error, and 'errno' is set to the value of the AX register returned by the system call. The number of sectors to read is limited to 64K or the size of the buffer, whichever is smaller .

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.

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.

#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:

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





Print an array in reverse order, we shall know the length of the array in advance. We can start an iteration from length value of array to zero and in each iteration we can print...


Zero on success or nonzero on failure. Seek from start of file. Seek from current location, seek from end of file, find proper structure, read the data into memory in c programming


Code read elements in an array from user and count total number of duplicate elements in array. C program code to find all duplicate elements in an unsorted array. How to list all


C program to read elements in a matrix and find determinant of the given matrix. Find determinant of a 2x2 matrix and 3x3 matrix. Logic to find determinant of a matrix in C.