9.2. Character Input/Output Functions

9.2.1. The fgetc function

Synopsis
#include <stdio.h>

int fgetc(FILE *stream );

Description

The fgetc function obtains the next character (if present) as an unsigned char converted to an int, from the input stream pointed to by stream, and advances the associated file position indicator for the stream (if defined).

Returns

The fgetc function returns the next character from the input stream pointed to by stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and fgetc returns EOF. If a read error occurs, the error indicator for the stream is set and fgetc returns EOF.

Implementation Notes

9.2.2. The fgets function

Synopsis
#include <stdio.h>

int fgets(char *s, int n, FILE *stream);

Description

The fgets function reads at most one less than the number of characters specified by n from the stream pointed to by stream into the array pointed to by s. No additional characters are read after a new-line character (which is retained) or after end-of-file. A null character is written immediately after the last character read into the array.

Returns

The fgets function returns s if successful. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.

Implementation Notes

9.2.3. The fputc function

Synopsis
#include <stdio.h>

int fputc(int c , FILE *stream );

Description

The fputc function is supported as specified in ANSI C 7.9.7.3.

Returns

The fputc function returns the character written. If a write error occurs the error indicator is set and fputc returns EOF.

Implementation Notes

9.2.4. The fputs function

Synopsis
#include <stdio.h>

int fputs(const char *s, FILE *stream);

Description

The fputs function writes the string pointed to by s to the stream pointed to by stream. The terminating null character is not written.

Returns

The fputs function returns EOF if a write error occurs: otherwise it returns a non-negative value.

Implementation Notes

9.2.5. The getc function

Synopsis
#include <stdio.h>

int getc(FILE *stream );

Description

The getc function is equivalent to fgetc, except that if it is implemented as a macro, it may evaluate stream more than once, so the argument should never be an expression with side effects.

Returns

The getc function returns the next character from the input stream pointed to by stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and fgetc returns EOF. If a read error occurs, the error indicator for the stream is set and getc returns EOF.

Implementation Notes

9.2.6. The getchar function

Synopsis
#include <stdio.h>

int getchar(void );

Description

The getchar function is equivalent to getc with the argument stdin.

Returns

The getchar function returns the next character from the input stream pointed to by stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and getchar returns EOF. If a read error occurs, the error indicator for the stream is set and getchar returns EOF.

Implementation Notes

9.2.7. The gets function

Synopsis
#include <stdio.h>

int gets(char *s );

Description

The gets function reads character from the input stream pointed to by stdin, into the array pointed to by s, until an end-of-file is encountered or a new-line character is read. any new-line character is discarded and a null character is written immediately after the last character read into the array.

Returns

The gets function returns s if successful. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the array contents are indeterminate and a null pointer is returned.

Implementation Notes

9.2.8. The putc function

Synopsis
#include <stdio.h>

int putc(int c , FILE *stream );

Description

The putc function is supported as specified in ANSI C 7.9.7.8.

Returns

The putc function returns the character written. If a write error occurs, the error indicator for the stream is set and putc returns EOF.

Implementation Notes

9.2.9. The putchar function

Synopsis
#include <stdio.h>

int putchar(intc );

Description

The putchar function is supported as specified in ANSI C 7.9.7.9.

Returns

The putchar function returns the character written. If a write error occurs, the error indicator for the stream is set and putchar returns EOF.

9.2.10. The puts function

Synopsis
#include <stdio.h>

int puts(const char *s );

Description

The puts function writes the string pointed to by s to the stream pointed to by stdout and appends a new-line character to the output. The terminating null character is not written.

Returns

The puts function returns EOF if a write error occurs: otherwise it returns a non-negative value.