Parse a simple inventory record in the form id,name,quantity into a struct. Reject missing fields, extra commas, an empty name, and a quantity outside 0..100000.
Requirements
Keep parsing separate from file I/O
Never write beyond fixed field capacities
Do not partially update the output on failure
Example
Input
7,keyboard,12
Expected output
success
Show a hint
Write down the input contract and the failure cases before coding.
local runtime
RUNTIME OUTPUT
Use your C runtime locally, then compare with solution.c.
Use your local runtime, then review the reference solution
LEARN FROM THE SOLUTION
Why the solution works.
Parsing into a local candidate preserves the output record when validation fails. The bounded conversion prevents a long name from overflowing the destination, and the field-count check makes malformed records fail before they reach the collection layer. In production, use a checked tokenizer when quoted commas must be supported.
What this exercise teaches
Mutable parsing buffers
Struct invariants
Layered validation
A PRACTICAL PLAN
Work through Parse one CSV inventory record with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.c.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.c only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Parse one CSV inventory record” teach?
This advanced C exercise focuses on Mutable parsing buffers, Struct invariants, Layered validation. Its requirements define the exact behavior to implement before you write code.
How should I validate this C solution?
Start with the displayed example input and expected output, then test a boundary case suggested by the requirements. Write and compile the starter in your local C environment, exercise the example and edge cases, then compare your approach with solution.c.
When should I open the reference solution?
Attempt Parse one CSV inventory record first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.