Use:
sscanf(source, "%*[^\t\n]", maxlen, target)
where maxlen is the size you want to read.
There appears to be no trivial way to make a format string for sscanf
(or any of it's siblings) take an arbitrary max length of the input string. The suggestion was based on printf
being orthogonal to scanf
, which turns out to not be the case.
You may find you have better luck using strtok
and either strncpy
or strdup
to copy the token.
However, since it's tagged C++, why not use:
std::stringstream ss(source);
std::string target;
getline(ss, target, "\t");