# Breaking a string into tokens

Is also called *split*, e.g., in Python and C#.

`char *strtok(char *str, const char *delim)`{l=c}:

Example:

:::{literalinclude} ../code/strtok.c
:language: c
:::
Output:
:::{literalinclude} ../code/strtok.txt
:language: text
:::
:::{warning}
`strtok` modifies the string it gets. It must not be a `const` string.

For example declaring the string as `char *text` will lead to a memory error `SIGSEGV: unvalid permissions for mapped object`, because the right side of the pointer becomes a constant string.
:::

1. On the first call we provide the text, in the next calls we provide `nullptr`. 
1. If we provide `nullptr`, `strtok` continues searching for tokens.
1. `strtok` returns `nullptr`, if no further tokens can be found.


:::{activity} Splitting into paragraphs and words
1. Modify the program above to separate it into words.
1. How would you split into paragraphs?
<!-- we have to buffer all `\n` tokens until we get `\n\n`. Then concatenate them. -->
:::