Contents 1 Overview 1.1 Functions 1.2 Constants 1.3 Variables 1.4 Member types 1.5 Extensions 2 Example 3 Alternatives to stdio 4 See also 5 References 6 External links

Overview[edit] Functions[edit] Most of the C file input/output functions are defined in stdio.h (or in the C++ header cstdio, which contains the standard C functionality but in the std namespace). Byte character Wide character Description File access fopen Opens a file (with a non-Unicode filename on Windows and possible UTF-8 filename on Linux) freopen Opens a different file with an existing stream fflush Synchronizes an output stream with the actual file fclose Closes a file setbuf Sets the buffer for a file stream setvbuf Sets the buffer and its size for a file stream fwide Switches a file stream between wide-character I/O and narrow-character I/O Direct input/output fread Reads from a file fwrite Writes to a file Unformatted input/output fgetc getc fgetwc getwc Reads a byte/wchar_t from a file stream fgets fgetws Reads a byte/wchar_t line from a file stream fputc putc fputwc putwc Writes a byte/wchar_t to a file stream fputs fputws Writes a byte/wchar_t string to a file stream getchar getwchar Reads a byte/wchar_t from stdin gets N/A Reads a byte string from stdin until a newline or end of file is encountered (deprecated in C99, removed from C11) putchar putwchar Writes a byte/wchar_t to stdout puts N/A Writes a byte string to stdout ungetc ungetwc Puts a byte/wchar_t back into a file stream Formatted input/output scanf fscanf sscanf wscanf fwscanf swscanf Reads formatted byte/wchar_t input from stdin, a file stream or a buffer vscanf vfscanf vsscanf vwscanf vfwscanf vswscanf Reads formatted input byte/wchar_t from stdin, a file stream or a buffer using variable argument list printf fprintf sprintf snprintf wprintf fwprintf swprintf Prints formatted byte/wchar_t output to stdout, a file stream or a buffer vprintf vfprintf vsprintf vsnprintf vwprintf vfwprintf vswprintf Prints formatted byte/wchar_t output to stdout, a file stream, or a buffer using variable argument list perror N/A Writes a description of the current error to stderr File positioning ftell ftello Returns the current file position indicator fseek fseeko Moves the file position indicator to a specific location in a file fgetpos Gets the file position indicator fsetpos Moves the file position indicator to a specific location in a file rewind Moves the file position indicator to the beginning in a file Error handling clearerr Clears errors feof Checks for the end-of-file ferror Checks for a file error Operations on files remove Erases a file rename Renames a file tmpfile Returns a pointer to a temporary file tmpnam Returns a unique filename Constants[edit] 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 eight _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 Variables[edit] Variables defined in the stdio.h header include: Name Notes stdin A pointer to a FILE which refers to the standard input stream, usually a keyboard. stdout A pointer to a FILE which refers to the standard output stream, usually a display terminal. stderr A pointer to a FILE which refers to the standard error stream, often a display terminal. Member types[edit] Data types defined in the stdio.h header include: FILE – also known as a file handle, this is an opaque type containing the information about a file or text stream needed to perform input or output operations on it, including: platform-specific identifier of the associated I/O device, such as a file descriptor the buffer stream orientation indicator (unset, narrow, or wide) stream buffering state indicator (unbuffered, line buffered, fully buffered) I/O mode indicator (input stream, output stream, or update stream) binary/text mode indicator end-of-file indicator error indicator the current stream position and multibyte conversion state (an object of type fpos_t) reentrant lock (required as of C11) fpos_t – a non-array type capable of uniquely identifying the position of every byte in a file and every conversion state that can occur in all supported multibyte character encodings size_t – an unsigned integer type which is the type of the result of the sizeof operator. Extensions[edit] The POSIX standard defines several extensions to stdio in its Base Definitions, among which are a readline function that allocates memory, the fileno and fdopen functions that establish the link between FILE objects and file descriptors, and a group of functions for creating FILE objects that refer to in-memory buffers.[4]

Example[edit] The following C program opens a binary file called myfile, reads five bytes from it, and then closes the file. #include <stdio.h> #include <stdlib.h> int main(void) { char buffer[5] = {0}; /* Initialized to zeroes */ int i; FILE *fp = fopen("myfile", "rb"); if (fp == NULL) { perror("Failed to open file \"myfile\""); return EXIT_FAILURE; } for (i = 0; i < 5; i++) { int rc = getc(fp); if (rc == EOF) { fputs("An error occurred while reading the file.\n", stderr); return EXIT_FAILURE; } buffer[i] = rc; } fclose(fp); printf("The bytes read were... %x %x %x %x %x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]); return EXIT_SUCCESS; }

Alternatives to stdio[edit] "Sfio" redirects here. For the defunct French political party, see French Section of the Workers' International. Several alternatives to stdio have been developed. Among these is the C++ iostream library, part of the ISO C++ standard. ISO C++ still requires the stdio functionality. Other alternatives include the Sfio (safe/fast string/file I/O) library from AT&T Bell Laboratories. This library, introduced in 1991, aimed to avoid inconsistencies, unsafe practices and inefficiencies in the design of stdio. Among its features is the possibility to insert callback functions into a stream to customize the handling of data read from or written to the stream.[5] It was released to the outside world in 1997.[6]

See also[edit] printf format string scanf format string

References[edit] ^ ISO/IEC 9899:1999 specification (PDF). p. 274, § 7.19.  ^ Kernighan, Brian; Pike, Rob (1984). The UNIX Programming Environment. Englewood Cliffs: Prentice Hall. p. 200.  ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.  ^ stdio.h – Base Definitions Reference, The Single UNIX Specification, Issue 7 from The Open Group ^ Korn, David G.; Vo, Kiem-Phong (1991). SFIO: Safe/Fast String/File IO. Proc. Summer USENIX Conf. CiteSeerX .  ^ Fowler, Glenn S.; Korn, David G.; Vo, Kiem-Phong (2000). Extended Formatting with Sfio. Proc. Summer USENIX Conf. 

External links[edit] The Wikibook C Programming has a page on the topic of: C Programming/C Reference v t e C programming language ANSI C C89 and C90 C99 C11 Embedded C MISRA C Features Functions Header files Libraries Operators String Syntax Preprocessor Data types Standard library functions Char (ctype.h) File I/O (stdio.h) Math (math.h) Dynamic memory (stdlib.h) String (string.h) Time (time.h) Variadic (stdarg.h) POSIX Standard libraries Bionic libhybris dietlibc EGLIBC glibc klibc Microsoft Run-time Library musl Newlib uClibc BSD libc Compilers Comparison of compilers ACK Borland Turbo C Clang GCC ICC LCC Pelles C PCC SDCC TCC Microsoft Visual Studio / Express / C++ Watcom C/C++ IDEs Comparison of IDEs Anjuta Code::Blocks CodeLite Eclipse Geany Microsoft Visual Studio NetBeans Comparison with other languages Compatibility of C and C++ Comparison with Embedded C Comparison with Pascal Comparison of programming languages Descendant languages C++ C# D Objective-C Alef Limbo Go Vala Category Retrieved from "" Categories: C standard libraryInput/outputHidden categories: Use dmy dates from January 2012Articles with example C code

Navigation menu Personal tools Not logged inTalkContributionsCreate accountLog in Namespaces ArticleTalk Variants Views ReadEditView history More Search Navigation Main pageContentsFeatured contentCurrent eventsRandom articleDonate to WikipediaWikipedia store Interaction HelpAbout WikipediaCommunity portalRecent changesContact page Tools What links hereRelated changesUpload fileSpecial pagesPermanent linkPage informationWikidata itemCite this page Print/export Create a bookDownload as PDFPrintable version Languages ČeštinaΕλληνικά한국어Русский中文 Edit links This page was last edited on 14 October 2017, at 23:18. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. Privacy policy About Wikipedia Disclaimers Contact Wikipedia Developers Cookie statement Mobile view (window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.260","walltime":"0.336","ppvisitednodes":{"value":1684,"limit":1000000},"ppgeneratednodes":{"value":0,"limit":1500000},"postexpandincludesize":{"value":42138,"limit":2097152},"templateargumentsize":{"value":1463,"limit":2097152},"expansiondepth":{"value":12,"limit":40},"expensivefunctioncount":{"value":2,"limit":500},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 271.972 1 -total"," 34.56% 93.982 1 Template:Reflist"," 19.93% 54.197 49 Template:Anchor"," 19.15% 52.089 2 Template:Cite_book"," 12.96% 35.249 1 Template:C_Standard_Library"," 11.73% 31.900 1 Template:Sidebar"," 8.10% 22.020 1 Template:Redirect"," 7.12% 19.358 1 Template:CProLang"," 5.92% 16.106 1 Template:Use_dmy_dates"," 5.78% 15.717 1 Template:Navbox"]},"scribunto":{"limitreport-timeusage":{"value":"0.109","limit":"10.000"},"limitreport-memusage":{"value":3284367,"limit":52428800}},"cachereport":{"origin":"mw1268","timestamp":"20180217152438","ttl":1900800,"transientcontent":false}}});});(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgBackendResponseTime":83,"wgHostname":"mw1269"});});

C_file_input/output - Photos and All Basic Informations

C_file_input/output More Links

C Standard LibraryC Data TypesC Character ClassificationC String HandlingC Mathematical FunctionsC Date And Time FunctionsC Localization FunctionsC Dynamic Memory AllocationC Process ControlC Signal HandlingC Alternative TokensAssert.hErrno.hSetjmp.hStdarg.hTemplate:C Standard LibraryTemplate Talk:C Standard LibraryC (programming Language)Standard LibrarySubroutineComputer FileInput/outputC Standard LibraryHeader FileMike LeskUnixVersion 7 UnixStream (computing)ByteRandom AccessFseekCategory:C Programming Language FamilyPHPErrno.hRename (computing)End-of-fileNull PointerStandard StreamsStandard StreamsStandard StreamsHandle (computing)Opaque PointerFile DescriptorC11 (C Standard Revision)Unsigned IntegerSizeofPOSIXFile DescriptorFrench Section Of The Workers' InternationalInput/output (C++)ISO C++AT&T Bell LaboratoriesCallback FunctionPrintf Format StringScanf Format StringBrian KernighanRob PikeThe UNIX Programming EnvironmentEnglewood CliffsPrentice HallDoug McIlroySingle Unix SpecificationThe Open GroupDavid Korn (computer Scientist)CiteSeerXTemplate:C Programming LanguageTemplate Talk:C Programming LanguageC (programming Language)ANSI CANSI CC99C11 (C Standard Revision)Embedded CMISRA CSubroutineInclude DirectiveCategory:C LibrariesOperators In C And C++C String HandlingC SyntaxC PreprocessorC Data TypesC Standard LibraryC Character ClassificationC Mathematical FunctionsC Dynamic Memory AllocationC String HandlingC Date And Time FunctionsStdarg.hC POSIX LibraryCategory:C Standard LibraryBionic (software)Hybris (software)DietlibcEmbedded GLIBCGNU C LibraryKlibcMicrosoft Windows Library FilesMuslNewlibUClibcBSD LibcCategory:C CompilersList Of CompilersAmsterdam Compiler KitBorland Turbo CClangGNU Compiler CollectionIntel C++ CompilerLCC (compiler)Pelles CPortable C CompilerSmall Device C CompilerTiny C CompilerMicrosoft Visual StudioMicrosoft Visual Studio ExpressVisual C++Watcom C/C++Category:Integrated Development EnvironmentsComparison Of Integrated Development EnvironmentsAnjutaCode::BlocksCodeLiteEclipse (software)GeanyMicrosoft Visual StudioNetBeansCategory:Comparison Of Individual Programming LanguagesCompatibility Of C And C++Embedded CComparison Of Pascal And CComparison Of Programming LanguagesC++C Sharp (programming Language)D (programming Language)Objective-CAlef (programming Language)Limbo (programming Language)Go (programming Language)Vala (programming Language)Category:C (programming Language)Help:CategoryCategory:C Standard LibraryCategory:Input/outputCategory:Use Dmy Dates From January 2012Category:Articles With Example C CodeDiscussion About Edits From This IP Address [n]A List Of Edits Made From This IP Address [y]View The Content Page [c]Discussion About The Content Page [t]Edit This Page [e]Visit The Main Page [z]Guides To Browsing WikipediaFeatured Content – The Best Of WikipediaFind Background Information On Current EventsLoad A Random Article [x]Guidance On How To Use And Edit WikipediaFind Out About WikipediaAbout The Project, What You Can Do, Where To Find ThingsA List Of Recent Changes In The Wiki [r]List Of All English Wikipedia Pages Containing Links To This Page [j]Recent Changes In Pages Linked From This Page [k]Upload Files [u]A List Of All Special Pages [q]Wikipedia:AboutWikipedia:General Disclaimer

view link view link view link view link view link