2013-12-31 08:59:14 +00:00
|
|
|
.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
|
|
|
.\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.\" Modified Fri Sep 8 15:48:13 1995 by Andries Brouwer (aeb@cwi.nl)
|
mmap.2, a64l.3, abort.3, abs.3, acos.3, acosh.3, addseverity.3, adjtime.3, aio_cancel.3, aio_error.3, aio_fsync.3, aio_read.3, aio_return.3, aio_suspend.3, aio_write.3, alloca.3, argz_add.3, asin.3, asinh.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atof.3, atoi.3, backtrace.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, btowc.3, byteorder.3, bzero.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, catgets.3, catopen.3, cbrt.3, ceil.3, cfree.3, cimag.3, clock_getcpuclockid.3, clog.3, clog10.3, closedir.3, confstr.3, conj.3, copysign.3, cos.3, cosh.3, cpow.3, cproj.3, creal.3, crypt.3, ctermid.3, daemon.3, des_crypt.3, difftime.3, dirfd.3, div.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, envz_add.3, erf.3, erfc.3, euidaccess.3, exec.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fclose.3, fcloseall.3, fdim.3, fenv.3, ferror.3, fflush.3, ffs.3, fgetc.3, fgetwc.3, fgetws.3, finite.3, flockfile.3, floor.3, fma.3, fmax.3, fmin.3, fmod.3, fmtmsg.3, fnmatch.3, fopen.3, fopencookie.3, fpclassify.3, fread.3, frexp.3, ftime.3, ftok.3, futimes.3, gamma.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrnam.3, getgrouplist.3, getloadavg.3, getlogin.3, getopt.3, getpass.3, getpt.3, getpwent.3, getpwnam.3, gets.3, getsubopt.3, getttyent.3, getusershell.3, getutmp.3, getw.3, gnu_get_libc_version.3, grantpt.3, hsearch.3, iconv.3, iconv_open.3, if_nametoindex.3, ilogb.3, index.3, inet.3, inet_pton.3, isalpha.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, j0.3, ldexp.3, lio_listio.3, localeconv.3, lockf.3, log.3, log10.3, log1p.3, log2.3, logb.3, lrint.3, lround.3, lseek64.3, makecontext.3, makedev.3, malloc.3, malloc_usable_size.3, matherr.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, mempcpy.3, memset.3, mkdtemp.3, mkfifo.3, mkstemp.3, modf.3, mq_close.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, nan.3, nextafter.3, nl_langinfo.3, opendir.3, posix_fallocate.3, posix_openpt.3, pow.3, pow10.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_equal.3, pthread_exit.3, pthread_getcpuclockid.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_sigqueue.3, pthread_testcancel.3, pthread_yield.3, ptsname.3, putenv.3, puts.3, putwchar.3, qecvt.3, raise.3, rand.3, random.3, random_r.3, re_comp.3, readdir.3, realpath.3, regex.3, remainder.3, remove.3, remquo.3, rewinddir.3, rexec.3, rint.3, round.3, rtime.3, scalb.3, scalbln.3, sched_getcpu.3, seekdir.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_post.3, sem_unlink.3, sem_wait.3, setbuf.3, setenv.3, siginterrupt.3, signbit.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sigwait.3, sin.3, sincos.3, sinh.3, sockatmark.3, sqrt.3, stdarg.3, stdio_ext.3, stpcpy.3, stpncpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcpy.3, strerror.3, strfmon.3, strfry.3, strftime.3, strlen.3, strnlen.3, strpbrk.3, strptime.3, strsep.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, termios.3, tgamma.3, timegm.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, towctrans.3, towlower.3, towupper.3, trunc.3, tsearch.3, ttyname.3, ttyslot.3, ualarm.3, ungetwc.3, unlockpt.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcspbrk.3, wcsrchr.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcswidth.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, y0.3, attributes.7, man-pages.7, standards.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-02 15:12:18 +00:00
|
|
|
.TH FGETC 3 2015-03-02 "GNU" "Linux Programmer's Manual"
|
2013-12-31 08:59:14 +00:00
|
|
|
.SH NAME
|
|
|
|
fgetc, fgets, getc, getchar, ungetc \- input of characters and strings
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdio.h>
|
|
|
|
.sp
|
|
|
|
.BI "int fgetc(FILE *" stream );
|
|
|
|
|
|
|
|
.BI "char *fgets(char *" "s" ", int " "size" ", FILE *" "stream" );
|
|
|
|
|
|
|
|
.BI "int getc(FILE *" stream );
|
|
|
|
|
|
|
|
.B "int getchar(void);"
|
|
|
|
|
|
|
|
.BI "int ungetc(int " c ", FILE *" stream );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
.BR fgetc ()
|
|
|
|
reads the next character from
|
|
|
|
.I stream
|
|
|
|
and returns it as an
|
|
|
|
.I unsigned char
|
|
|
|
cast to an
|
|
|
|
.IR int ,
|
|
|
|
or
|
|
|
|
.B EOF
|
|
|
|
on end of file or error.
|
|
|
|
.PP
|
|
|
|
.BR getc ()
|
|
|
|
is equivalent to
|
|
|
|
.BR fgetc ()
|
|
|
|
except that it may be implemented as a macro which evaluates
|
|
|
|
.I stream
|
|
|
|
more than once.
|
|
|
|
.PP
|
|
|
|
.BR getchar ()
|
|
|
|
is equivalent to
|
|
|
|
.BI "getc(" stdin ) \fR.
|
|
|
|
.PP
|
|
|
|
.BR fgets ()
|
|
|
|
reads in at most one less than
|
|
|
|
.I size
|
|
|
|
characters from
|
|
|
|
.I stream
|
|
|
|
and stores them into the buffer pointed to by
|
|
|
|
.IR s .
|
|
|
|
Reading stops after an
|
|
|
|
.B EOF
|
|
|
|
or a newline.
|
|
|
|
If a newline is read, it is stored into the buffer.
|
|
|
|
A terminating null byte (\(aq\e0\(aq)
|
|
|
|
is stored after the last character in the buffer.
|
|
|
|
.PP
|
|
|
|
.BR ungetc ()
|
|
|
|
pushes
|
|
|
|
.I c
|
|
|
|
back to
|
|
|
|
.IR stream ,
|
|
|
|
cast to
|
|
|
|
.IR "unsigned char" ,
|
|
|
|
where it is available for subsequent read operations.
|
|
|
|
Pushed-back characters
|
|
|
|
will be returned in reverse order; only one pushback is guaranteed.
|
|
|
|
.PP
|
|
|
|
Calls to the functions described here can be mixed with each other and with
|
|
|
|
calls to other input functions from the
|
|
|
|
.I stdio
|
|
|
|
library for the same input stream.
|
|
|
|
.PP
|
|
|
|
For nonlocking counterparts, see
|
|
|
|
.BR unlocked_stdio (3).
|
|
|
|
.SH RETURN VALUE
|
|
|
|
.BR fgetc (),
|
|
|
|
.BR getc ()
|
|
|
|
and
|
|
|
|
.BR getchar ()
|
|
|
|
return the character read as an
|
|
|
|
.I unsigned char
|
|
|
|
cast to an
|
|
|
|
.I int
|
|
|
|
or
|
|
|
|
.B EOF
|
|
|
|
on end of file or error.
|
|
|
|
.PP
|
|
|
|
.BR fgets ()
|
|
|
|
returns
|
|
|
|
.I s
|
|
|
|
on success, and NULL
|
|
|
|
on error or when end of file occurs while no characters have been read.
|
|
|
|
.PP
|
|
|
|
.BR ungetc ()
|
|
|
|
returns
|
|
|
|
.I c
|
|
|
|
on success, or
|
|
|
|
.B EOF
|
|
|
|
on error.
|
2015-02-26 02:40:09 +00:00
|
|
|
.SH ATTRIBUTES
|
|
|
|
For an explanation of the terms used in this section, see
|
|
|
|
.BR attributes (7).
|
|
|
|
.TS
|
|
|
|
allbox;
|
|
|
|
lbw25 lb lb
|
|
|
|
l l l.
|
|
|
|
Interface Attribute Value
|
|
|
|
T{
|
|
|
|
.BR fgetc (),
|
|
|
|
.BR fgets (),
|
|
|
|
.BR getc (),
|
|
|
|
.br
|
|
|
|
.BR getchar (),
|
|
|
|
.BR ungetc ()
|
|
|
|
T} Thread safety MT-Safe
|
|
|
|
.TE
|
|
|
|
|
2013-12-31 08:59:14 +00:00
|
|
|
.SH CONFORMING TO
|
2015-04-18 07:01:31 +00:00
|
|
|
POSIX.1-2001, POSIX.1-2008, C89, C99.
|
2013-12-31 08:59:14 +00:00
|
|
|
|
|
|
|
It is not advisable to mix calls to input functions from the
|
|
|
|
.I stdio
|
|
|
|
library with low-level calls to
|
|
|
|
.BR read (2)
|
|
|
|
for the file descriptor associated with the input stream; the results
|
|
|
|
will be undefined and very probably not what you want.
|
|
|
|
.SH SEE ALSO
|
|
|
|
.BR read (2),
|
|
|
|
.BR write (2),
|
|
|
|
.BR ferror (3),
|
|
|
|
.BR fgetwc (3),
|
|
|
|
.BR fgetws (3),
|
|
|
|
.BR fopen (3),
|
|
|
|
.BR fread (3),
|
|
|
|
.BR fseek (3),
|
|
|
|
.BR getline (3),
|
2013-12-31 10:01:24 +00:00
|
|
|
.BR gets (3),
|
2013-12-31 08:59:14 +00:00
|
|
|
.BR getwchar (3),
|
|
|
|
.BR puts (3),
|
|
|
|
.BR scanf (3),
|
|
|
|
.BR ungetwc (3),
|
|
|
|
.BR unlocked_stdio (3),
|
|
|
|
.BR feature_test_macros (7)
|