Skip to content

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Oct 13, 2025

Resolves #552

Changes:

  • Added (v)sscanf. Follows most of the C23 standard, with some exceptions (see below)
  • Added PRI*24 and SCN*24 to <inttypes.h>
  • strtof, strtod, and strtold now set endptr correctly when there are no digits or an empty exponent field.
/**
 * (v)sscanf
 * Originally based off of https://github.com/tusharjois/bscanf
 * @note All non-suppressed character sequence types must have a maximum field width:
 *  - Valid   : "%*3c %*8s %*12[^abc]"
 *  - Valid   : "%3c  %8s  %12[^abc]"
 *  - Valid   : "%*c  %*s  %*[^abc]"
 *  - Invalid : "%c   %s   %[^abc]"
 * @note ranges such as "%5[0-9]" or "%5[^a-z]" are not supported
 * @note `wchar_t` is not supported
 * @warning invalid floating point strings are not handled correctly.
 * Under the C standard, "100e" should fail to match to "%f" (since the
 * exponent field may not be empty), and no value should be assigned. However,
 * nano_scanf incorrectly matches "100e" to "%f", assigning a value of 100
 * instead of exiting.
 */

Other notes:

  • %a and %A are disabled since strto(f/d/ld) doesn't support C99 hexadecimal floats
  • The maximum scan buffer is currently set to 40, so %39d will work but %40d and larger will cause (v)sscanf to exit (The scan buffer does not apply to %d which can read an unlimited amount of characters). The stack-frame will blow up if I set the value too high, leading to inefficient code generation (frameset has to be less than 127 bytes).

@adriweb
Copy link
Member

adriweb commented Oct 13, 2025

Wow nice, lots of tests too 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add sscanf

2 participants