home *** CD-ROM | disk | FTP | other *** search
- /*
- * getline.c
- * contains: getline()
- *
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- /*
- * int
- * getline(str,max)
- *
- * ARGUMENT
- * (char *) str = Destination string
- * (int) max = Maximum number of characters to transfer
- *
- * DESCRIPTION
- * Get a line of text from stdin.
- *
- * Text is copied from stdin to the destination string until:
- * 1. a newline is encountered, or
- * 2. a NULL character is input.
- * In any event the output string is terminated with '\0'.
- *
- * RETURNS
- * Integer length of string.
- *
- * AUTHOR
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
- int GF_CONV getline(str,imax)
- char *str;
- int imax;
- {
- int i;
- char c;
-
- i=0;
- while(--imax&&(c=(char)getchar())!=EOF&&c!='\n'&&c!='\0') {
- *str++=c;
- i++;
- }
- if(c=='\n'||c=='\0') {
- *str++ = '\n';
- *str= '\0';
- return i;
- }
- return i;
- }
-