INI Config Reader
Build a command-line program in C that reads INI configuration files, the simple format with [sections] and key = value lines used by many programs. You'll be able to ask for a value, for example ./iniread app.ini server port, list every section and key, and check a file for errors. The program reports mistakes with the line number, such as a line without =, a key outside any section or a duplicate key. It's a solid beginner project in C: reading a file line by line, working with strings, storing data in structs and arrays, and building with Make.
- Estimate
- ~9h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Make · POSIX
Project roadmap
- 01
Set up the project
~1hCreate src/main.c and a Makefile that compiles with -Wall -Wextra -std=c11 and has build, clean and test targets. Add example files to examples/: a valid config with two sections and several keys, and one with mistakes. The program prints usage when started with no arguments. Done when: make builds the program and running it without arguments prints the usage.
- 02
Read the file line by line
~1.5hOpen the file with fopen and read it line by line with fgets into a buffer (lines up to 512 characters). Write a trim function that removes leading and trailing spaces and the newline. Skip empty lines and comment lines starting with ; or #. Print an error and exit with code 1 if the file can't be opened. Done when: the program prints every meaningful line of the example file, trimmed.
- 03
Parse sections and keys
~2hRecognize [section] lines and key = value lines, trimming spaces around the key and value. Store entries in an array of structs with section, key and value fields (fixed-size char arrays are fine), growing the array with realloc when needed. Done when: after parsing the valid example, the program holds every entry with the right section.
- 04
Report errors with line numbers
~1.5hReport problems as file:line: message: a line that is neither a section nor key = value, a key before any section, an empty key, a section header without the closing ], and a duplicate key within the same section. Collect all errors instead of stopping at the first, and exit with code 1 when any are found. Done when: the broken example prints each mistake with its correct line number.
- 05
Add the commands
~1.5hSupport three commands: iniread FILE SECTION KEY prints the value (exit code 2 if it isn't found), iniread FILE --list prints every entry as section.key = value, and iniread FILE --check prints OK or the errors. Section and key names are compared without regard to upper or lower case. Done when: all three commands work on the example files.
- 06
Test it
~1.5hWrite tests/run.sh, called by make test, that runs the program on the example files and compares its output and exit codes with expected results. Cover: getting a value, a missing key, listing, and each kind of error. Done when: make test passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack