Header Files in C- Language
The C-language has a large set of header files as the standard library. The standard C-library is full of library functions. In the standard library, several header files are present. Each header file has the extension name '.h.'.
Each header file has the collection of several functions which Can perform many tasks such as input/output operations, arithmetic operations. These functions are useful for repeatedly use of some operations.
The functions which are related in operations are kept in one header file. In any C-program, to use a function from the standard library, the related header file must be included in the program. Some commonly used header files and their functions are discussed below:
Content In This Blog
Explain Header Files
- ctype.h
- string.h
- math.h
- stdio.h
- stdlib.h
- dos.h
- times.h
(1) ctype.h :
The functions of "ctype.h" are related with character type conversion and character type testing. Following are the common functions of ctype.h-
Return Type |
Function |
Deacription |
---|---|---|
int |
isalnum(int |
Return nonzero for alphanumerical character (A-Z, a-z, 0-9) otherwise return zero |
int |
isalpha(int var) |
Retums nonzero if the given character is alphabet otherwise returns zero. |
int |
isdigit(int var) |
Returns nonzero if the given argument is a digit (0-9) otherwise returns zero. |
int |
islower(int var) |
Returns nonzero if the argument is lower character case otherwise returns zero. |
int |
isupper(int var) |
Returns nonzero if the given argument is upper case character. For others returns zero. |
int |
isspace(int var) |
Returns nonzero if the given character is white space like new line, horizontal/vertical tab, space, carriage return, form feed, etc. |
int |
isxdigit(int var) |
It returns nonzero value if the argument is hexadecimal digit (A-F, a-f, 0-9). |
int |
isascii(int var) |
Check the given character is ASCII character (from 0 to 0X7F) or not. Returns nonzero for ASCII. |
int |
iscontrol(int var) |
Check the given character in control character (from 0 to 0X1F and 0X7F (DEL) or not. Returns nonzero for control character. |
int |
isgraph(int var) |
Check the given character is graphic character (any character, not space) or not and returns nonzero for such character. |
int |
isprint(int var) |
Check the given character is printable or not. The printable characters are from 0X20 to 0X7E. Returns nonzero for True checking. |
int |
ispunct(int var) |
Returns nonzero if the given character is punctuation or space. |
int |
tolower(int var) |
COnverts the upper case character (A-Z) into its equivalent lower case character (a-z). |
int |
toupper(int var) |
Converts the lower case character (a-z) to the equivalent upper character (A-Z). |
(2) string.h:
The "string.h" header file contains the string manipulation functions. The string is the collection of characters. Several functions of "string.h" provide the facility to manipulate the string. Some of such functions are described as follows -
Return Type |
Function |
Description |
---|---|---|
int |
strlen(char *var) |
Return the number of character in given string |
int |
strcmp(char *var1, char *var2) |
|
int |
strcmpi(char *var1, char *var2) |
Compares two string lexicographically with case sensitivity. |
char |
*strcat(char *string1, char *string2) |
Concatenates (joins) two given string and stores the concatenation result into first string. |
char |
*strcpy(char *string1, char *string2) |
Copies second string on to the first string. |
char |
*strcpy(char *string1, char *string2) |
Similar to strcpy() function. |
char |
*strchr(char *string, int arg) |
Returns positions to the first occurrence of the two arguments in the given string. Return NULL. |
char |
*strcoll(char *string1, char *string2) |
Similar to strcmp() function. |
strcspn |
(char *string1, char *string2) |
Returns the position of first character of stringl which is matched with any character of string2. |
char |
*strdup(char *string1, char *string2) |
Used for copying a string at the allocated memory which is pointed by pointer variable. |
char |
*strerror(int num) |
Used for printing the error message. It takes the global variable errno as the argument and displays the error message related to the error number. |
char |
*strlwr(char *string) |
Converts the characters of string into upper case characters. Converts the characters of string into upper case characters. |
char |
*strupr(char *string) |
Concatenates the characters of string specified by length. |
char |
*strncat(char *S1, char *s2, int n) |
Compare the character of string specified length. |
char |
*strrev(char *string) |
Reverse all characters of string. |
(3) math.h :
This header file has the collection of many functions which help in mathematical calculations. Some common functions of "math.h. are as follows -
Return Type |
Function |
Description |
---|---|---|
int |
abs(int var) |
Returns the absolute value of the argument that means only numeric value regardless of its sign either positive or negative. |
double |
acos(double var) |
Returns the trignometric arc cosine of the given argument (from -1 to +1). The return value is in Radians between Zero and pi. |
double |
asin(double var) |
Compute the arc sine of the argument (from -1 to +1) and returns value between -pi and +pi/2. |
double |
atan(double var) |
Compute the arc tangent of the argument given in the range of -1 and +1. The return value is in Radians between -pi/2 and +pi/2. |
double |
atan2(double var1, double var2) |
Compute the arc tangent of var1/var2. varl is the y-axis and var2 is x-axis. It returns the value in quadrants. |
double |
cabs(double var) |
Returns the absolute value of the complex number. There is a structure defined for complex numbers. |
double |
ceil(double var) |
Returns the nearest integer greater than or equals to the given number.e.g.,If var = 2.3 then Returns 3If var = -2.3 then Returns -2 |
double |
cos(double var) |
Returns trignometric cosine of the given number (in Radians) as the value from -1 to +1. |
double |
cosh(double var) |
Computes the hyperbolic cosine for the number value given in radians. |
double |
exp(double var) |
Computes the value of exponent numbers (as e^var). Here e is the natural logarithm between 2 and 3. |
double |
fabs(double var) |
Computes the absolute value of the given floating point number, that means floating point number without sign. |
double |
floor(double var) |
Returns the nearest integer lesser than or equals to the given floating point number.e.g.If var = 2.3 Returns 2If var = 2.3 Returns -3 |
double |
fmod(double var1, double var2) |
Similar to modulus operator and returns remainder of the division varl/var2). |
double |
hypot(double var1, double var2) |
Computes the hypotenus of the right angle triangle. varl and var2 are the length of the other sides of the triangle. |
double |
log(double var) |
Computes the natural logarithm (base e) of the given number. |
double |
log10(double var) |
Computes the common logarithm (base 10) of the given number. |
double |
modf(double var, double *p) |
Decompose the real number into integer and fractional part and returns the fractional part and p takes integer part. |
double |
pow(double var1, double var2) |
Computes the value of varl^var2 that means by raising var2 as the power to the varl. |
double |
pow10(int var) |
Computes the value of 10^var. |
double |
sin(double var) |
Computes the trignometric sine of the given var value (in radians). |
double |
sinh(double var) |
Computes the hyperbolic sine of given radian value. |
double |
sqrt(double var) |
Computes the square root of the given numeric value. |
double |
tan(double var) |
Computes the trignometric tangent of the radian argument value. |
double |
tan(double var) |
Computes the hyperbolic tangent of the given radian argument value. |
(4) stdio.h :
The header file named "stdio.h" has the collection of input/output functions. These functions are associated with keyboard input/file input and screen output/file output. Some common input/output functions supported by "stdio.h" are as follows :
Return Type | Function | Description |
---|---|---|
int | fctose(FILE *ptr) | Closes a file pointed by the pointer ptr and returns zero for successful closing. |
int | feof(FILE *ptr) | Determines the end of file pointed by pointer ptr and returns nonzero value when end of file has been reached. |
int | ferror(FILE *ptr) | Detects the error during File operations. |
int | fflush(FILE *ptr) | Removes or flush out any data remaining in the buffer. The argument required by this function must be the buffer such as "stdin' is the buffer related to the standard input device-keyboard. |
int | fgetc(FILE *ptr) | Reads a character from a file pointing by the FILE pointer. |
char | fgets(char *string, int n, FILE *ptr) | Reads a string from the file pointed by file pointer for a specified length. |
int | filelength(int fd) | Used for getting the length of a file denoted by an integer fd. |
FILE | *fopen(const char *fname, const char *mode) | Opens a file of given name in specified working mode otherwise returns NULL. |
int | fprintf(FILE *ptr, char *format, variables) | Write the values of different variables to the file pointing by FILE pointer. It and requires variables as arguments. |
int | fputc(int var, FILE *ptr) | Writes the given character to the file pointing by ptr. |
int | fputs(char *string, FILE *ptr) | Sends the given string to the file pointed by ptr. |
int | fputchar(int var) | Writes a character to the standard output device. |
int | fread(void *var, sizeof var, int n, FILE *ptr) | row13 col 3 |
int | free(void *ptr) | row14 col 3 |
int | fscanf(FILE *ptr, char *format, variables) | row15 col 3 |
int | fseek(FILE *ptr, long disp, int pos) | row16 col 3 |
long int | ftell(FILE *ptr) | row17 col 3 |
int | fwrite(void *var, sizeof (var), int n, FILE *ptr) | Writes the data to a file pointed by ptr. |
int | getc(FILE *ptr) | Reads a single character from the file pointed by pointer(ptr). |
int | getchar( ) | Reads single character from the standard input device such as keyboard. |
char | *gets(char *string) | Reads a string from the standawrd input device keyboard. |
int | printf(char *format, variables) | Sends the data items stored in variables to the sdtandard output device (monitor/screen). |
int | putc(char var, FILE *ptr) | Writes a single character to a file. |
int | putchar(char var) | Writes a single character to the standard output device. Writes a string with space to the standard output device. |
int | puts(char *string) | Writes a string with space to the standard output device. |
int | remove(char *fname) | Deletes a file specified by Filename and returns zero for success. |
int | rename(char *old, char *new) | Rename a file with new filename and returns zero for success. |
int | rewind(FILE *ptr) | Moves the file pointer to the beginning of file. |
int | scanf(char *format, variables) | Reads the data from standard input device and store to the respective variables. |
(5) stdlib.h :
The common functions of this header file are as follows:
Return Type | Function | Description |
---|---|---|
double | atoi(char *string) | Converts string to the double precision numbers (float). |
int | atoi(char *string) | Converts string to an integer. Converts string to long integer. |
long | atol(char *string) | Converts the given integer to string type. |
exit | (int n) | Closes all files and buffer and terminate the program. It require zero as, argument for successful termination of the program. |
char | *iota(int var) | Converts the given integer to string type. |
char | *ltoa(long var) | Converts given long data value to the string type. |
int | system(char *command) | Pass the command to the operating system and returns zero for successful execution of the command. |
int | rand( ) | Return the random positive numbers. |
(6) dos.h:
The function of "dos.h" operates only where the dos environment is used as output window for C-language.
Return Type | Function | Description |
---|---|---|
delay(int ms) | ||
sound(int frequency) | Generates a sound on PC speaker for the given frequency (Hz or MHz) | |
nosound( ) | Converts the given integer to string type. |
(7) time.h:
This header file is associated with the date and time related functions, some of them are as follows :
Return Type | Function | Description |
---|---|---|
long | time( ) | Returns the current system time as ling integer. |
int | difftime(time1, time2) | Computes the difference between two given times. |
char | *strdate( ) | Returns current system date as string. |
char | strtime( ) | Returns current system time as string |