No way to parse integers in C

C users are melting down after a coder says even reading a simple number is a trap

TLDR: A programmer says C’s built-in number-reading tools are so unreliable that even simple input can go weird or fail silently. The comments turned into a culture war: some called the library hopelessly broken, while others snapped that real C programmers should just build their own fix.

A programmer dropped a grenade into the C language crowd by arguing that its built-in ways to turn text like “123” into an actual number are, basically, all a mess. The complaint is simple enough for non-coders to feel: if you type a number, the computer should read the whole thing, reject junk like “123timmy,” and clearly tell you when something went wrong. Instead, the article says some old-school C tools can silently give the wrong answer, shrug at bad input, or behave in bizarre ways when numbers get too big. One unsigned-number function even accepts a minus sign and turns it into a giant positive number, which sent readers into full "are you kidding me" mode.

But the real fireworks were in the comments, where the community split into two very online camps: “this proves C’s standard library is cursed” versus “stop whining and write your own parser.” One commenter bluntly declared that basically everything involving strings in C is bad and you should bring your own tools. Another went full grizzled-veteran energy, saying that back in 1983, fixing broken string functions was literally homework. And then came the eye-roll brigade: one annoyed C fan called the article “bad faith” and insisted the language itself isn’t the problem—just its dusty old built-in library. The funniest moment? Someone casually posted a tiny homemade loop as if this whole meltdown could be solved with a few lines and a prayer. In other words: classic programming drama—ancient design, modern rage, and everyone convinced they’re the only sane person in the thread.

Key Points

  • The article argues that C standard-library integer parsing functions do not consistently provide strict, reliable conversion behavior for whole-string numeric input.
  • It says `atol()` is unsafe because invalid input and overflow are not adequately reportable, and unrepresentable values are described as undefined behavior by C and POSIX.
  • The article presents `strtol()` as usable for signed integers only if the caller checks for empty input, resets and inspects `errno`, and verifies that no trailing characters remain.
  • The article states that `strtoul()` and related unsigned parsers accept leading minus signs and can return wrapped unsigned results instead of errors.
  • An update notes that C++'s `std::from_chars()` appears to be a useful alternative for integer parsing.

Hottest takes

"everything related to strings in C stdlib ... is bad" — zokier
"fixing all of them" — bsenftner
"C is not the C standard library, ffs" — stephc_int13
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.