FGETSMOD

Section: Standard I/O Functions (3S)
Updated: 11 May 1986
Index Return to Main Contents
 

NAME

fgetsmod - get a line from a stream, truncating it if it is too long  

SYNOPSIS

#include <stdio.h>
#define TOOLONG -2

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

DESCRIPTION

Fgetsmod is a modified version of fgets, which truncates lines longer than the size of the array into which they are being read. It reads n-2 characters, or up to a newline character, whichever comes first, from the stream into the string s. If no newline is found after reading the first n-2 characters, fgetsmod will add a newline and null character, then read and discard characters from the input stream up to a newline. In other words, it will discard characters in excess of the capacity of s. The last character read into s is followed by a null character. Fgetsmod returns the number of characters read if it can read the whole line.  

SEE ALSO

gets(3S), puts(3S), getc(3S), scanf(3S), fread(3S), ferror(3S)  

AUTHOR

Mohamed el Lozy, Harvard Health Sciences Computing Faility  

DIAGNOSTICS

Fgetsmod return the integer zero upon end of file or read error. It returns -2 (to avoid confusion with EOF) if the line is too long.  

BUGS

Fgetsmod returns an int, unlike fgets, which returns a char. It should therefore probably return EOF on end of file, but returning zero makes it more similar to fgets.


 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
AUTHOR
DIAGNOSTICS
BUGS

This document was created by man2html, using the manual pages.
Time: 06:38:27 GMT, December 12, 2024