C PROGRAMMING · FILE HANDLING

Manage Every
Contact.
In Pure C.

A lightweight, file-based contact management application written in C — designed with reliability, simplicity and modular software principles.

No database. No framework. Just C structures, file I/O and your own logic. This project taught me how real applications manage persistent data at the lowest level — the same principles that power every embedded data storage system.

5
OPERATIONS
FILE
PERSISTENCE
0
LIBRARIES
C
LANGUAGE
ADDRESSBOOK — CONTACTS
addressbook — manu@linux
MENU
AM
Amar C M
+91 98765 43210
SAVED
AS
Anand Sir
+91 87654 32109
SAVED
BP
Balgopal P
+91 76543 21098
SAVED
SP
Srivatsa P
+91 65432 10987
SAVED
fopen · fread · fwrite · fclose
// HOW IT WORKS

File-Based Persistence

Every contact is stored as a C structure written directly to a binary file. No database. The entire persistence layer is built using fopen, fread, fwrite and fclose — giving full control over how data is read, modified and saved.

01
Store as a C Structure
Each contact is a struct with name, phone and email fields. The struct is written directly to a binary file using fwrite. Reading is done with fread — no parsing needed.
fwrite(&contact, sizeof(Contact), 1, fp)
02
Edit Using File Reconstruction
To edit or delete a record, every contact is read into memory, the target is modified or skipped, and all records are written to a temporary file which replaces the original.
fseek(fp, offset, SEEK_SET)
03
Search & Validate
Search reads through every record sequentially comparing names or phone numbers using strcmp(). Input validation prevents empty fields, duplicate entries and invalid phone numbers from being saved.
strcmp(contact.name, query)
// OPERATIONS FLOW

Read & Write Operations

Two core file operations power the entire application. Reading loads contacts for display and search. Writing handles add, edit and delete by rebuilding the file safely.

READ — DISPLAY & SEARCH
1
Open contacts file in binary read mode
fopen("contacts.dat", "rb")
2
Read one struct at a time into memory
fread(&c, sizeof(Contact), 1, fp)
3
Display or compare against search query
strcmp(c.name, query) == 0
4
Continue until end of file
while (!feof(fp))
5
Close file after reading
fclose(fp)
FILE I/O
WRITE — ADD, EDIT & DELETE
1
Open original file and a temp file
fopen("contacts.dat", "rb")
2
Read each contact into memory
fread(&c, sizeof(Contact), 1, fp)
3
Skip deleted / write modified record
fwrite(&updated, sizeof(Contact), 1, tmp)
4
Replace original with temp file
remove("contacts.dat") + rename()
5
Close all file pointers
fclose(fp) + fclose(tmp)
// KEY FEATURES

What It Does

Add Contacts
Stores name, phone number and email as a C struct written directly to a binary file. Input validation prevents empty fields and duplicate phone numbers.
🔍
Search Contacts
Searches through all stored contacts sequentially by name or phone number using strcmp(). Returns matching records with full details displayed.
✏️
Edit Contacts
Modifies existing records using safe temporary file reconstruction. The original file is replaced only after the new file is fully and correctly written.
🗑️
Delete Contacts
Removes a contact by rebuilding the file without the deleted record. No direct line deletion — the entire file is reconstructed safely every time.
💾
Persistent Storage
All contacts are stored in a binary file and persist across program executions. No database needed — pure file I/O using fread and fwrite in C.
🧱
Modular Architecture
Separate functions for add, view, search, edit, delete and validation. Each function has a single responsibility — clean, readable and maintainable code.
// TECH STACK

Built With

LANGUAGE
C Programming
Pure C with no external libraries. Every operation — contact storage, file reconstruction, input validation — built entirely from scratch.
STORAGE
File Handling
fopen, fread, fwrite, fclose and fseek for binary file operations. Contacts stored as raw structs — no text parsing, no format overhead.
DATA
C Structures
Contact struct holds name, phone and email. Struct written and read directly as binary — efficient, compact and perfectly aligned with the file layout.
STRINGS
String Operations
strcmp() for search and duplicate detection. strcpy() for safe field copying. strlen() for input length validation before writing to file.
DESIGN
Modular Programming
Each operation in its own function. Input validation separated from business logic. Menu-driven interface cleanly separated from file operations.
PLATFORM
Linux / GCC
Compiled with GCC using -Wall -Wextra for zero warnings. Developed and tested on Linux. Compatible with any POSIX-compliant environment.
ABOUT
DEV
Manu H P
Embedded Systems Trainee — Emertxe

AddressBook was my first real C project at Emertxe Information Technology — built during my Advanced C Programming module. It taught me how persistent storage works without a database, how to handle file reconstruction safely, and why defensive programming matters when data integrity is the goal. Every principle here carries directly into embedded systems work.

C Programming File Handling Data Structures Modular Design Linux Embedded Systems
INSTITUTE
Emertxe Information Technology
MODULE
Advanced C Programming — First Project
GUIDED BY
Anand Lokhande Sir
Jagadeesan S Sir
Sapthagiri Shanmugam Sir