Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Do you have a test? There're no comments in the code. It's in general not a good idea to use untested and publish untested or uncommented code - not matter whether it's common practice. The possibility to review revisions is also limited on this platform, consider an explicit code hosting platform. Commented Jun 16, 2015 at 9:22
  • @KarlRichter tests were a good idea to add. I found the old version choked on '\0' characters. This version should work (passes a few basic tests at least). Commented Jun 16, 2015 at 12:14
  • 1
    fgets gets a line, not a buffer-full. You're scanning the 4096-byte full buffer for each line read from stdin. You need fread here, not fgets. Commented Jun 16, 2015 at 13:43
  • @StéphaneChazelas great - didn't know of fread (seldom do I/O from C). updated example to use fread instead. Commented Jun 17, 2015 at 11:00
  • I've added an if block around the printf statements, that makes the output more readable if some bytes don't occur in the input file: gist.github.com/martinvonwittich/… Commented Jun 4, 2016 at 11:08