C file input/output: Difference between revisions

Content deleted Content added
Functions: Added content
Tags: Mobile edit Mobile web edit
No edit summary
Tags: Mobile edit Mobile app edit iOS app edit App section source
 
(2 intermediate revisions by 2 users not shown)
Line 247:
int main(void) {
char buffer[5];
size_t len;
FILE* fp = fopen("myfile", "rb");
 
Line 254 ⟶ 255:
}
 
if ((len = fread(buffer, 1, 5, fp)) < 50) {
fclose(fp);
fputs("An error occurred while reading the file.\n", stderr);
Line 263 ⟶ 264:
 
printf("The bytes read were: ");
for (int i = 0; i < 5len; ++i) {
printf("%02X ", buffer[i]);
}
Line 275 ⟶ 276:
{{Redirect|Sfio|other uses of "SFIO"|SFIO (disambiguation)}}
 
Several alternatives to {{mono|stdio}} have been developed. Among these is theare [[Input/output (C++)|C++ {{mono|iostream}}I/O]] libraryheaders <code><iostream></code> and <code><print></code>, part of the [[ISO C++|ISO C++ standard]]. ISO C++ still requires the {{mono|stdio}} functionality.
 
Other alternatives include the Sfio<ref>{{Cite web |url=http://akpublic.research.att.com/sw/tools/sfio/ |title=Sfio: A Safe/Fast I/O Library |access-date=16 March 2021 |archive-date=11 February 2006 |archive-url=https://web.archive.org/web/20060211021834/http://akpublic.research.att.com/sw/tools/sfio/ |url-status=bot: unknown }}</ref> (A Safe/Fast I/O Library) library from [[AT&T Bell Laboratories]]. This library, introduced in 1991, aimed to avoid inconsistencies, unsafe practices and inefficiencies in the design of {{mono|stdio}}. Among its features is the possibility to insert [[callback function]]s into a stream to customize the handling of data read from or written to the stream.<ref>{{cite conference |title=SFIO: Safe/Fast String/File IO |first1=David G. |last1=Korn |author-link=David Korn (computer scientist) |first2=Kiem-Phong |last2=Vo |conference=Proc. Summer USENIX Conf. |year=1991 |citeseerx=10.1.1.51.6574}}</ref> It was released to the outside world in 1997, and the last release was 1 February 2005.<ref>{{cite conference |first1=Glenn S. |last1=Fowler |first2=David G. |last2=Korn |first3=Kiem-Phong |last3=Vo |title=Extended Formatting with Sfio |conference=Proc. Summer USENIX Conf. |year=2000}}</ref>