:::{video} ../img/filter-csv-by-age.webm
:figwidth: 500px
:align: right
:caption: Demonstration of the program. Warning: `cat` is not available on Powershell. I used it to show the content of files, which you can use the editor for. I mistyped some of the `cat` commands and did not use them. Moreover, the usage string in the beginning is incorrect, but is fixed in the template below.
:::

# Filter CSV by age

Implement a program that filters people by age from a dataset.

Input data is a comma-separated values (CSV) file. If there is a row which does not contain two columns, then output an error message.

:::{wpd} Comma-separated values
plain text data format for storing tabular data where the values of a record are separated by a comma and each record is a line.
:::

Milestones:
1. First begin by processing `people-with-age.csv` line by line. If you encounter a blank line, then warn the user, but continue processing by printing the non-blank lines.

   ```sh
   ./main.exe 15 people-with-age.csv
   ```

1. Parse one line into tokens and filter by age
1. Recognize the three different malformed lines

   1. Whole line missing
   1. Age missing (no token)
   1. Age not recognized (token cannot be converted to a number)
   
1. Support output to a file

   ```
   ./main.exe people-with-age.csv out.csv
   ```

1. Also support reading the input from `stdin` as follows:

   `````{tab-set}
   ````{tab-item} Powershell
   ```powershell
   "Anna, 12" | ./main.exe 15
   ```
   ````
   ````{tab-item} Linux
   ```sh
   echo "Anna, 12" | ./main.exe 15
   ```
   ````
   `````

`people-with-age.csv`:
```{literalinclude} ../code-wi/people-with-age.csv
:language: text
```

The output file must not contain any error messages.

:::{literalinclude} ../code-wi/masked/filter-csv-by-age.c
:language: c
:::

Requirements:
- Deliver a very general flowchart where at least the line by line processing is visible, but not how each error is recognized.

Some concepts used from previous chapters:
- Section {ref}`main-arguments`