Static Wikipedia February 2008 (no images)

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

Web Analytics
Cookie Policy Terms and Conditions Stdio.h - Wikipedia, the free encyclopedia

Stdio.h

From Wikipedia, the free encyclopedia

C++ Standard Library headers
C Standard Library headers
assert.h
complex.h
ctype.h
errno.h
fenv.h
float.h
inttypes.h
iso646.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdarg.h
stdbool.h
stddef.h
stdint.h
stdio.h
stdlib.h
string.h
tgmath.h
time.h
wchar.h
wctype.h
The correct title of this article is stdio.h. The initial letter is shown capitalized due to technical restrictions.

stdio.h, which stands for "standard input-output header," is the header in the C standard library for the C programming language which 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 M.E. Lesk at Bell Labs in the early 1970s.[citation needed] C++ also has its own implementation of the functions from C for compatibility reasons, which are declared in the 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 which 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 many of its derivatives are declared in from header files. Thus, programmers have to include the stdio.h header into the source code to utilize the functions declared there.

 #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 the standard input and echo it onto the standard output, line by line.

[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 (ends at newline or null character)
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 different sized data from a file
fwrite writes different sized 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, fprintf, sprintf, snprintf used to print to stdout
vprintf also used to print to stdout
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, fscanf, sscanf used to input from stdin
vfscanf, vscanf, vsscanf also used to input from stdin
setbuf
setvbuf sets the buffering mode for a given stream
tmpnam creates a temporary filename and stores it in its first argument (a char *)
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:
    • 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.
In other languages
Static Wikipedia 2008 (no images)

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 -

Static Wikipedia 2007 (no images)

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 -

Static Wikipedia 2006 (no images)

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 - 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