Re: fgets not doing as I expect.
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 26 Dec 2008 16:21:41 -0500
Andrew McMeikan wrote:
I wanted to limit how many chars I read in, but the code below
instead of stopping at 7 chars will happily read 30 or 40 car
lines and spit them out. Not what I expected. Any pointers?
Yes. Start by reading the description of fgets. Then also correct
your postings so that lines do not exceed 72 chars (67 is better).
7.19.7.2 The fgets function
Synopsis
[#1]
#include <stdio.h>
char *fgets(char * restrict s, int n,
FILE * restrict stream);
Description
[#2] 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
[#3] 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.
--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
.
- References:
- fgets not doing as I expect.
- From: Andrew McMeikan
- fgets not doing as I expect.
- Prev by Date: Re: Type-checking casts for GNU C
- Next by Date: Re: Type-checking casts for GNU C
- Previous by thread: Re: fgets not doing as I expect.
- Index(es):
Relevant Pages
|