Unit - V C Programming
Unit - V C Programming
FILE
Pre processor
C preprocessor is a micro processor that is used by #if
compiler to transform your code before
compilation. It is called micro preprocessor #else
because it allows us to add macros.
#elif
All preprocessor directives starts with hash #
symbol. #endif
list of preprocessor directives. #error
#include
#pragma
#define
#undef
#ifdef
#ifndef
Macros
A macro is a segment of code which is replaced by the value of macro.
Macro is defined by #define directive. There are two types of macros:
Object-like Macros
Function-like Macros
Object-like Macros
The object-like macro is an identifier that is replaced by value. It is
widely used to represent numeric constants. For example:
#define PI 3.14
Here, PI is the macro name which will be replaced by the value 3.14.
Function-like Macros
The function-like macro looks like function call. For example:
#define MIN(a,b) ((a)<(b)?(a):(b))
Here, MIN is the macro name.
C Predefined Macros
ANSI C defines many predefined macros that can be used in c program.
When dealing with files, there are two types of files you should know
about:
Text files
Binary files
1. Text files ( Stream oriented data)
Text files are the normal .txt files. You can easily create text files using
any simple text editors such as Notepad.
When you open those files, you'll see all the contents within the file as
plain text. You can easily edit or delete the contents.
2. Binary files (system
oriented data)
Binary files are mostly the .bin files in your computer.
Instead of storing data in plain text, they store it in the binary form (0's
and 1's).
The following operations
can be performed on a
file.
Creation of a new file (fopen with attributes as “a” or “a+” or “w” or
“w++”)
Opening an existing file (fopen)
Reading from file (fscanf or fgets)
Writing to a file (fprintf or fputs)
Moving to a specific location in a file (fseek, rewind)
Closing a file (fclose)
Functions for file
handling
No. Function Description