On Fri, Sep 19, 2025 at 4:59 AM Sven Schreiber
<sven.schreiber(a)fu-berlin.de> wrote:
 Am 19.09.2025 um 10:38 schrieb Riccardo (Jack) Lucchetti:
 On 19/09/2025 10:07, Sven Schreiber wrote:
 <hansl>
 string hey = "aha oho, uhu"
 string s
 sscanf(hey, "aha %s", s) # expected: "oho, uhu"
 print s # gives "oho,"
 </hansl>
 This function is really borrowed from the standard C library. From its man page:
       s       Matches  a  sequence  of  non-white-space  characters; the  next
               pointer must be a pointer to the initial element of  a character
               array that is long enough to hold the input sequence and the ter‐
               minating null byte ('\0'), which is added automatically.  The in‐
               put  string  stops  at white space or at the maximum field width,
               whichever occurs first.
 so the space effectively end the string that the function catches. I guess (haven't
tested) that in C you could use "%[a-z, ]" do do what you want, but it appears
we have a bug that prevents this from working properly in hansl.
 About the whitespace: OK, good to know where it comes from, but the question is whether
we want to have this behavior at the hansl level. AFAIK, in hansl the format code %s
stands for an arbitrary string, including whitespace. At least it doesn't seem to be
documented. 
IMO it's best to stick with the C behavior for sscanf. Apart from
anything else, changing it would be backward-incompatible.
Below, a few ways of getting what you originally wanted:
<hansl>
string hey = "aha oho, uhu"
string s1
sscanf(hey, "aha %31[^\n]", s1) # scan up to newline, if present
printf "s1 = '%s'\n", s1
s2 = hey[5:]
printf "s2 = '%s'\n", s2
string s3
sscanf(hey, "%*s %31[^\n]", s3) # discard first space-separated string
printf "s3 = '%s'\n", s3
</hansl>
Allin