Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C file input/output
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example== The following C program opens a binary file called ''myfile'', reads five bytes from it, and then closes the file. <syntaxhighlight lang="c"> #include <stdio.h> #include <stdlib.h> int main(void) { char buffer[5]; FILE* fp = fopen("myfile", "rb"); if (fp == NULL) { perror("Failed to open file \"myfile\""); return EXIT_FAILURE; } if (fread(buffer, 1, 5, fp) < 5) { fclose(fp); fputs("An error occurred while reading the file.\n", stderr); return EXIT_FAILURE; } fclose(fp); printf("The bytes read were: "); for (int i = 0; i < 5; ++i) { printf("%02X ", buffer[i]); } putchar('\n'); return EXIT_SUCCESS; } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)