C/C++ Arena

Step 7 of 7

Challenge: a CSV report

A realistic batch job: read input data, aggregate it, write an output file.

sales.csv starts with a header line, then region,amount rows (amounts are whole dollars). Your turn:

  1. Skip the header, then total the amounts per region (at most 10 regions, names up to 15 characters), keeping regions in the order they first appear.
  2. Write report.txt with one REGION TOTAL line per region.
  3. Then read report.txt back and print it, so the test can see what you wrote.

Tip: sscanf(line, "%15[^,],%d", region, &amount) reads everything up to the comma as the region, then the number.

Previous: Safe formatting with snprintf