Introduction
A contact manager is a small application with many details to get right: validation that rejects bad data without frustrating the user, sorting that ignores case, and a storage format that survives commas and spaces.
Problem statement
Objectives
- Write validation functions for real-world formats
- Maintain a sorted dynamic array
- Implement case-insensitive compare and search
- Use tab-separated text for robust storage
Features
- Phone and email validation with re-prompting
- Case-insensitive sorting, duplicate detection and search
- Edit and delete by exact name
- Filter by city
- Tab-separated file storage
Concepts demonstrated
- Input validation
- Sorting
- String processing
- Dynamic memory
System architecture
A single module keeps contacts in a heap array that is re-sorted with qsort after each insertion. icmp/icontains implement case-insensitive comparison. The file stores one contact per line with tab separators, parsed back with %[^\t] scansets.
Folder structure
Complete source code
Makefile
What each file does
- src/main.c
- Validation (
valid_phone,valid_email), storage, sorting, search and the menu. - Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 Ravi Kumar 9876543210 ravi@example.com Hyderabad 1 Anita Desai 12345 9123456780 anita.desai@mail anita.desai@mail.com Pune 1 meera iyer +918008001234 meera@kenholt.in hyderabad 2 3 IYER 6 Hyderabad 5 Ravi Kumar 2 0
Testing
- Diff with
tests/expected-output.txt(includes rejected phone and email entries). - Add "zara" then "Aditi" and check that the list stays alphabetical regardless of case.
- Restart and confirm contacts are reloaded.
Common errors
Contacts with spaces in the city are cut off
The last field is read with %31[^\n], which keeps spaces; check you didn't change it to %s.
Search misses "Iyer" when typing "iyer"
Use the case-insensitive icontains, not strstr, for names and emails.
Possible improvements
- Import/export vCard (.vcf)
- Multiple phone numbers per contact
- Group contacts with tags
Additional challenges
- 1Add fuzzy search that tolerates one typo (Levenshtein distance ≤ 1).
- 2Detect duplicate phone numbers across different names.
- 3Replace the array with a binary search tree keyed by name.
Built and tested it yourself? Mark it to update your dashboard.