In this tutorial you will be familiarize with header file, commonly used header files and the predefined function declared in them.
The files having ‘.h’ as extension are called header file.
These header file generally contain declaration of predefined/in-built functions.
Header file “stdio.h” contains declaration of function printf() which is an in-built function to display output on console screen.
Now, let us discuss how to include a header file in program??
Syntax to include a header file in program is explained below :
Lines that starting with # specifies pre-processor.
In the above example, pre-processor copies the pre-processed code of library file “stdio.h” to the current file.
So let us flick through some commonly used header files and the declared pre-defined functions too.
- <ctype.h> : This header file contains functions to determine the type of data contained in character.
|isalpha||checks the condition if a character is alphabetic or not|
|islower||checks the condition if a character is lowercase or not|
|isupper||checks the condition if a character is an uppercase character or not|
|isdigit||checks the condition if a character is a digit or not|
|isxdigit||checks the condition if a character is a hexadecimal character or not|
|isspace||checks the condition if a character is a space character or not|
|ispunct||checks the condition if a character is a punctuation character or not|
|tolower||converts a character to lowercase i.e. TOE = toe|
|toupper||converts a character to uppercase i.e. to = TO|
- <math.h> : This header file contains common mathematical functions.
|abs||computes absolute value of an integral value (|x|)|
|fabs||computes absolute value of a floating-point value (|x|)|
|exp||calculates e raised to the given power (ex)|
|exp2||computes 2 raised to the given power (2x)|
|log||computes natural (base-e) logarithm (ln(x))|
|log10||computes common (base-10) logarithm (log10(x))|
|log2||computes base-2 logarithm (log2(x))|
|pow||computes a number raised to the given power (xy)|
|sqrt||computes square root (√x)|
|sin||computes sine (sin(x))|
|cos||computes cosine (cos(x))|
|tan||computes tangent (tan(x))|
|sinh||computes hyperbolic sine (sinh(x))|
|cosh||computes hyperbolic cosine (cosh(x))|
|tanh||computes hyperbolic tangent|
3. <stdbool.h> : This header file contains Boolean operations.
|Macro name||Expands to|
|true||integer constant 1|
|false||integer constant 0|
Example of the Boolean operations :
bool a=true, b=false
4. <stdio.h> : This header file contains standard Input and output operations along with file handling.
|fclose||closes a file|
|fread||reads from a file|
|fwrite||writes to a file|
|fgetc||gets a character from a file|
|fgets||gets a character string from a file|
|fputc||writes a character to a file|
|fputs||writes a character string to a file|
|getchar||reads a character from stdin|
|gets||reads a character string from stdin|
|putchar||writes a character to stdout|
|puts||writes a character string to stdout|
|scanf||reads formatted input from stdin|
|printf||prints formatted output to stdout|
stdin : standard input
stdout : standard output
5. <stdlib.h> : This header file contains standard library files like memory management.
|calloc||allocates and zeroes memory|
|realloc||expands previously allocated memory block|
|free||de-allocates previously allocated memory|
6. <string.h> : This header file contains string manipulation operations.
|strcpy||copies one string to another|
|strcat||concatenates two strings|
|strlen||returns the length of a given string|
|strcmp||compares two strings|