ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
stdio.h - Wikipedia, the free encyclopedia

stdio.h

From Wikipedia, the free encyclopedia

C Standard Library headers

stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations. The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s.[1] C++, for compatibility reasons, includes stdio.h as well as an essentially equivalent header, cstdio.

Functions declared in stdio.h are extremely popular, since as a part of the C standard library, they are guaranteed to work on any platform that supports C. Applications on a particular platform might, however, have reasons to use the platform's I/O routines, rather than the stdio.h routines.

Contents

[edit] Example usage

All functions in C (and its many derivatives) are declared in header files. Thus, programmers have to include the stdio.h header in the source code in order to use the functions declared in it.

#include <stdio.h>
 
int main(void)
{
    int ch;
    while ((ch = getchar()) != EOF)
        putchar(ch);
    putchar('\n');
    return 0;
}

The above program reads all input from standard input and echoes it to standard output, byte by byte, adding a newline at the end of its output.

[edit] Member functions

Functions declared in stdio.h can generally be divided into two categories: the functions for file manipulation and the functions for input-output manipulation.

Name Notes
File manipulation functions
fclose closes a file associated with the FILE * value passed to it
fopen, freopen, fdopen opens a file for certain types of reading or writing
remove removes a file (deletes it)
rename renames a file
rewind acts as if fseek(stream, 0L, SEEK_SET) was called for the stream passed, and then its error indicator cleared
tmpfile creates and open a temporary file, which is deleted when closed with fclose()
Input-output manipulation functions
clearerr clears end-of-file and error indicators for a given stream
feof checks whether an end-of-file indicator has been set for a given stream
ferror checks whether an error indicator has been set for a given stream
fflush forces any pending buffered output to be written to the file associated with a given stream
fgetpos stores the file position indicator of the stream associated by its first argument (a FILE *) to its second argument (a fpos_t *)
fgetc returns one character from a file
fgets gets a string from the file (ending at newline or end-of-file)
fputc writes one character to a file
fputs writes a string to a file
ftell returns a file-position indicator which can then be passed to fseek
fseek seeks through a file
fsetpos sets the file position indicator of a stream associated by its first argument (a FILE *) as stored in its second argument (a fpos_t *)
fread reads data from a file
fwrite writes data to a file
getc reads and returns a character from a given stream and advances the file position indicator; it is allowed to be a macro with the same effects as fgetc, except that it may evaluate the stream more than once
getchar has the same effects as getc(stdin)
gets reads characters from stdin until a newline is encountered and stores them in its only argument
printf, vprintf used to print to the standard output stream
fprintf, vfprintf used to print to a file
sprintf, snprintf, vsprintf used to print to a char array (C string)
perror writes an error message to stderr
putc writes and returns a character to a stream and advances the file position indicator for it; it is allowed to be a macro with the same effects as fputc, except that it may evaluate the stream more than once
putchar, fputchar has the same effects as putc(stdout)
scanf, vscanf used to input from the standard input stream
fscanf, vfscanf used to input from a file
sscanf, vsscanf used to input from a char array (e.g., a C string)
setbuf
setvbuf sets the buffering mode for a given stream
tmpnam creates a temporary filename
ungetc pushes a character back onto a stream
puts outputs a character string to stdout

[edit] Member constants

Constants defined in the stdio.h header include:

Name Notes
EOF a negative integer of type int used to indicate end-of-file conditions
BUFSIZ an integer which is the size of the buffer used by the setbuf() function
FILENAME_MAX the size of a char array which is large enough to store the name of any file that can be opened
FOPEN_MAX the number of files that may be open simultaneously; will be at least 8
_IOFBF an abbreviation for "input/output fully buffered"; it is an integer which may be passed to the setvbuf() function to request block buffered input and output for an open stream
_IOLBF an abbreviation for "input/output line buffered"; it is an integer which may be passed to the setvbuf() function to request line buffered input and output for an open stream
_IONBF an abbreviation for "input/output not buffered"; it is an integer which may be passed to the setvbuf() function to request unbuffered input and output for an open stream
L_tmpnam the size of a char array which is large enough to store a temporary filename generated by the tmpnam() function
NULL a macro expanding to the null pointer constant; that is, a constant representing a pointer value which is guaranteed not to be a valid address of an object in memory
SEEK_CUR an integer which may be passed to the fseek() function to request positioning relative to the current file position
SEEK_END an integer which may be passed to the fseek() function to request positioning relative to the end of the file
SEEK_SET an integer which may be passed to the fseek() function to request positioning relative to the beginning of the file
TMP_MAX the maximum number of unique filenames generable by the tmpnam() function; will be at least 25

[edit] Member variables

Variables defined in the stdio.h header include:

Name Notes
stdin a pointer to FILE which refers to the standard input stream, usually a keyboard.
stdout a pointer to FILE which refers to the standard output stream, usually a display terminal.
stderr a pointer to FILE which refers to the standard error stream, often a display terminal.

[edit] Member types

Data types defined in the stdio.h header include:

  • FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including:
    • a file descriptor
    • the current stream position
    • an end-of-file indicator
    • an error indicator
    • a pointer to the stream's buffer, if applicable
  • fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file.
  • size_t - an unsigned integer type which is the type of the result of the sizeof operator.

[edit] See also

[edit] References

  1. ^ Kernighan, Brian; Rob Pike (1984). The UNIX Programming Environment. Englewood Cliffs: Prentice Hall, pg. 200. 
Languages


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -