Well, this isn't really an answer to your question, but just a note. You ought to define c with the type int since char can't represent EOF when it's unsigned (and it will usually clash with another...