213 lines · 3.9 KB · Text
RawDownload
.TH FGETC 2.SH NAMEfgetc, getc, getchar, fputc, putc, putchar, ungetc, fgets, gets, fputs, puts, fread, fwrite \- Stdio input and output.SH SYNOPSIS.B #include <u.h>.br.B #include <stdio.h>.ta \w'\fLlong 'u.PP.Bint	fgetc(FILE *f).PP.Bint	getc(FILE *f).PP.Bint	getchar(void).PP.Bint	fputc(int c, FILE *f).PP.Bint	putc(int c, FILE *f).PP.Bint	putchar(int c).PP.Bint	ungetc(int c, FILE *f).PP.Bchar	*fgets(char *s, int n, FILE *f).PP.Bchar	*gets(char *s).PP.Bint	fputs(char *s, FILE *f).PP.Bint	puts(char *s).PP.Blong	fread(void *ptr, long itemsize, long nitems, FILE *stream).PP.Blong	fwrite(void *ptr, long itemsize, long nitems, FILE *stream).SH DESCRIPTIONThe functions described here work on open Stdio streams (see.IR fopen )..PP.I Fgetcreturns as an.B intthe next.B unsigned.B charfrom input stream.IR f .If the stream is at end-of-file, the end-of-file indicator for thestream is set and.I fgetcreturns.BR EOF .If a read error occurs, the error indicator for the stream is set and.I fgetcreturns.BR EOF ..I Getcis like.I fgetcexcept that it is implemented as a macro..I Getcharis like.I getcexcept that it always reads from.BR stdin ..PP.I Ungetcpushes character.I cback onto the input stream.BR f .The pushed-back character will be returned by subsequent reads inthe reverse order of their pushing.A successful intervening.IR fseek ,.IR fsetpos ,or.I rewindon.I fdiscards any pushed-back characters for.IR f .One character of push-back is guaranteed..I Ungetcreturns the character pushed back (converted to.B unsigned.BR char ),or.B EOFif the operation fails.A successful call to.I ungetcclears the end-of-file indicator for the stream.The file position indicator for the stream after reading or discardingall pushed-back characters is the same as it was before thecharacters were pushed back..PP.I Fputcwrites character.I c(converted to.B unsigned.BR char )to output stream.IR fat the position indicated by the position indicator for the streamand advances the indicator appropriately.If the file cannot support positioning requests, or if the stream wasopened with append mode, the character is appended to the output stream..I Fputcreturns the character written or.B EOFif there was a write error..I Putcis like.IR fputcbut is implemented as a macro..I Putcharis like.I putcexcept that it always writes to.BR stdout ..PPAll other input takes place as if characters were read by successivecalls to.I fgetcand all other output takes place as if characters were written bysuccessive calls to.IR fputc ..PP.I Fgetsreads up to and including the next newline, but not past end-of-fileor more than.IR n -1characters, from stream.I finto array.IR s .A null character is written immediately after the last character readinto the array (if any characters are read at all)..I Fgetsreturns.I sif successful, otherwise a null pointer..I Getsis similar to.IR fgetsexcept that it always reads from.B stdinand it discards the terminating newline, if any..I Getsdoes not check for overflow of the receiving array, so its use is deprecated..PP.I Fputswrites the string.I sto  stream.IR f ,returning.B EOFif a write error occurred, otherwise a nonnegative value.The terminating null character is not written..I Putsis the same, writing to.BR stdout ..PP.I Freadreads from the named input.IR stream at most.I nitemsof data of size.I itemsizeand the type of.I *ptrinto a block beginning at.IR ptr .It returns the number of items actually read..PP.I Fwriteappends to the named output.I streamat most.I nitemsof data of size.I itemsizeand the type of.I *ptrfrom a block beginning at.IR ptr .It returns the number of items actually written..SH SOURCE.B /sys/src/libstdio.SH "SEE ALSO".IR read (2), .IR fopen (2),.IR bio (2).SH BUGSStdio does not handle.SM UTFor runes; use Bio instead.