The CSV files are comma separated values. If you want a comma inside the value, you have to surround it with quotes.
Your example in CSV, as you need your output, should be:
msg = "1,2, \"Hello , how are you \"";
so the value Hello , how are you
is surrounded with quotes.
This is the standard CSV. This has nothing to do with the behaviour of the strtok
function.
The strtok
function just searches, without considering anything else, the tokens you have passed to it, in this case the ,
, thus it ignores the "
.
In order to make it work as you want, you would have to tokenize with both tokens, the ,
and the "
, and consider the previous found token in order to decide if the ,
found is a new value or it is inside quotes.
NOTE also that if you want to be completely conforming with the CSV specification, you should consider that the quotes may also be escaped, in order to have a quote character inside the value term. See this answer for an example:
Properly escape a double quote in CSV
NOTE 2: Just for completeness, here is the CSV specification (RFC-4180): https://www.rfc-editor.org/rfc/rfc4180