getchar - return EOF; } /* * Cast through unsigned char, to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <stdio.h> #include <unistd.h> /* * C standard I/O function - read character from stdin * and return it or the symbolic constant EOF (-1). */ int getchar(void) { char ch; int len; len = read(STDIN_FILENO, &ch, 1); if (len<=0) { /* end of file or error */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return EOF; } /* * Cast through unsigned char, to prevent sign extension. This * sends back values on the range 0-255, rather than -128 to 127, * so EOF can be distinguished from legal input. */ return (int)(unsigned char)ch; }...
View Full Document

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Ask a homework question - tutors are online