Computer Programming C: UNIT V: File Operations

Header Files in C Programming

Types, Examples

In C programming, a header file is a file that ends with the ".h" extension and contains features like functions, data types, macros, etc.

HEADER FILES IN C

 

Introduction

In C programming, a header file is a file that ends with the ".h" extension and contains features like functions, data types, macros, etc that can be used by any other C program by including that particular header file using "#include" preprocessor.

C language uses header files to provide the standard libraries and their components for use in programs.

// Adding standard input and output library by

// including stdio.h header file

#include <stdio.h>

int main()

{

        // printf() function from stdio.h header file

        printf("Hello");

        return 0;

}

OUTPUT

Hello

EXPLANATION: In the above program, we have included the stdio.h header file that provides the standard input and output library in C.

// for header files in system/default directory

#include <filename.h>

// for Header files in same directory as source file

#include "filename.h"

The #include preprocessor directs the compiler that the header file needs to be processed before compilation and includes all the necessary data types and function definitions.

#include <stdio.h>  → Standard header file in System directory

#include "filename.h"   → User defined header file in source file directory

int main()

{

         ……..

         ……..

}

 

Types of C Header Files

There are two types of 'header files in C:

• Standard / Pre‒existing header files

• Non‒standard / User‒defined header files

 

1. Standard Header Files in C

Standard header files contain the libraries defined in the ISO standard of the C programming language. They are stored in the system directory of the compiler and are present in all the C compilers from any vendor.

There are plenty of standard header files in the latest version of C language. Following is the list of some commonly used header files in C. Header File

<assert.h>: It contains information for adding diagnostics that aid program debugging.

<errno.h>: It is used to perform error handling operations like errno(), strerror(), perror(), etc.

<float.h>: It contains a set of various platform‒dependent constants related to floating point values.

<math.h>: It is used to perform mathematical operations like sqrt(), log20), pow(), etc.

<signal.h>: It is used to perform signal handling functions like signal() and raise().

<stdarg.h>: It is used to perform standard argument functions like va_start() and va_arg(). It is also used to indicate start of the variable‒length argument list and to fetch the arguments from the variable‒length argument list in the program respectively.

<ctype.h>: It contains function prototypes for functions that test characters for certain properties, and also function prototypes for functions that can be used to convert uppercase letters to lowercase letters and vice versa.

<stdio.h>: It is used to perform input and output operations using functions like scanf(), printf(), etc.

<setjump.h>: It contains standard utility functions like malloc(), realloc(), etc. It contains function prototypes for functions that allow bypassing of the usual function call and return sequence.

<string.h>: It is used to perform various functionalities related to string manipulation like strlen(), strcmp(), strcpy(), size(), etc.

<limits.h>: It determines the various properties of the various variable types. The macros defined in this header limits the values of various variable types like char, int, and long. These limits specify that a variable cannot store any value beyond these limits, for example, an unsigned character can store up to a maximum value of 255.

<time.h>: It is used to perform functions related to date() and time() like setdate() and getdate(). It is also used to modify the system date and get the CPU time respectively.

<stddef.h>: It contains common type definitions used by C for performing calculations.

<locale.h>: It contains function prototypes and other information that enables a program to be modified for the current locale on which it's running. It enables the computer system to handle different conventions for expressing data such as times, dates, or large numbers throughout the world.

Example: Demonstrates the use of some commonly used header files in C.

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int main()

{

char s1[20] = "12345";

char s2[10] = "Geeks";

char s3[10] = "VRBMUNI";

long int res;

//Find the value of 9^3 using a function in math.h library

Res =  pow(9, 3);

printf("Using math.h, ""The value is: %ld\n", res);

//Convert a string to long long int using a function in stdlib.h library

long int a=atol(s1);

printf("Using stdlib.h, the string");

printf(" to long int: %ld\n", a);

//Copy the string s3 into s2 using using a function in string.h library

strcpy(s2,s3);

printf("Using string.h, the strings" "s2 and s3:%s%s\n", s2,53);

return 0;

OUTPUT

Using math.h, The value is: 729

Using stdlib.h, the string to long int: 12345

Using string.h, the strings s2 and s3: VRBMUNI VRBMUNI

 

2. Non‒Standard Header Files

Non‒standard header files are not part of the language's ISO standard. They are generally all the header files defined by the programmers for purposes like containing custom library functions etc or provided as external libraries by different vendors. They are manually installed by the user or maybe part of the compiler by some specific vendor.

Example: Demonstrates the use of conio.h non‒standard header file.

#include <stdio.h>

#include <conio.h>

// Function to display a welcome message

void displayMessage()

{

        printf("Hello! VRBMUNI\n");

}

int main()

{

// Using conio.h functions

printf("Press any key to print message \n");

// Wait for a key press

getch();

// Call the additional function after a key press

display Message();

return 0;

}

OUTPUT

Press any key to print message

Hello! VRBMUNI

Computer Programming C: UNIT V: File Operations : Tag: Computer Science : Types, Examples - Header Files in C Programming


Computer Programming C: UNIT V: File Operations



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation