Settings

Theme

No way to parse integers in C (2022)

blog.habets.se

14 points by konmok 3 hours ago · 3 comments

Reader

bsenftner a minute ago

One of the first homework assignments when I learned C back in '83 was after a long lecture on how the string functions are fundamentally broken, and the class introduction to writing C was fixing all of them.

voidUpdate 13 minutes ago

Cant you just:

  for(int i = 0; i < len(characters); i++)
  {
    if(characters[i]-48 <= 9 && characters[i]-48 >= 0)
    {
      ret = ret \* 10 + characters[i] - 48;
    }
    else
    {
      return ERROR;
    }
  }
  return ret;
Adjust until it actually works, but you get the picture.
zokier 21 minutes ago

I thought it was pretty well known that everything related to strings in C stdlib (including all str... functions) is bad. You just need to bring in your own string library.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection