How to use the fwirte function in C language
Today, the editor will share with you the relevant knowledge points about how to use the fwirte function in c language. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
1. The fwrite function is used to write buffer data to the file and return the number of elements successfully written to the file. If an error occurs or the end of the file is reached, it may be less than nmemb.
2. The fwrite function does not distinguish between the tail of the file and the error, so the caller must use feof and ferror to determine what happened.
Example
# include # include int main () {FILE * fp; char c [] = "www.codersrc.com"; char buffer [2048] = {0}; / * Open the file for reading and writing * / fp = fopen ("file.txt", "w +"); / * write data to the file * / fwrite (c, strlen (c) + 1, 1, fp) / * offset to the beginning of the file * / fseek (fp, 0, SEEK_SET); / * read and display data * / fread (buffer,1, strlen (c) + 1, fp); printf ("% s\ n", buffer); fclose (fp); return (0);} these are all the contents of the article "how to use fwirte functions in c language". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.