home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
c
/
croutes.zip
/
GETLINE.C
< prev
next >
Wrap
Text File
|
1980-01-01
|
1KB
|
45 lines
/* *** getline.c *** */
/* */
/* IBM - PC microsoft "C" */
/* */
/* Function to read a record from a file into a string. Returns the */
/* length of the string including the NULL, an EOF if EOF is reached,*/
/* or a -1 if an error occured. */
/* */
/* Written by L. Cuthbertson, March 1984. */
/* */
/*********************************************************************/
/* */
#include <stdio.h>
int getline(fp,line,len)
char line[];
int len;
FILE *fp;
{
int c,inlen;
/* read character at a time */
for(inlen=0;(((c=getc(fp)) != '\r') && (c != '\n'));inlen++) {
/* error checking */
if (inlen >= len) return (-1);
/* EOF check */
if (c == EOF) {
line[inlen] = NULL;
return(EOF);
}
/* move character into line */
line[inlen] = c;
}
/* replace CR or NL with a NULL */
line[inlen] = NULL;
/* done */
return(inlen+1);
}