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*

20
  • 2
    That's definitely a valid correction, but the OP claims that they get errors before their bad fclose() call. Commented Aug 27 at 20:36
  • 1
    @gregspears I've now fixed the error (thanks for pointing it out) but the program still fails for me when taking piped input. In fact, it does so at the first while loop, where both file streams (stdin and fp) are tagged by ferror(). I find this very unusual, considering it works with piping at a Linux command prompt. Are you on Windows? If so, which compiler are you using? Commented Aug 27 at 20:43
  • 1
    This sounds like a potential line-endings problem. Make sure all of your uses of stdio functions are using binary mode. Commented Aug 27 at 20:54
  • 2
    I've built my example using both the Microsoft Visual C++ 2010 and Open Watcom 1.1 compilers. Executables generated by both accept pipes without a peep. Looks like a specific compiler issue, given Borland's is the only one making problematic binaries. Thanks to all who took the time to look and to reply. I'll hold off closing this thread for a few days, in case someone has other ideas. Commented Aug 27 at 22:59
  • 3
    Don’t return negative numbers from your program. Return values in the range 0..126, inclusive. 1 is the usual choice, which in C programs you can get just by using the EXIT_FAILURE macro. Commented Aug 28 at 2:19