How to use fwirte function in C language
This article mainly explains "how to use the fwirte function in c language", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "how to use the fwirte function in c language"!
The fwrite function writes buffer data to a file and returns 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.
The fwrite function does not distinguish between the end of a file and an error, so the caller must use feof and ferror to determine what happened.
examples
#include #include int main(){ FILE *fp; char c[] = "www.codersrc.com"; char buffer[2048] = {0}; /* Open file for reading and writing */ fp = fopen("file.txt", "w+"); /* Write data to file */ fwrite(c, strlen(c) + 1, 1, fp); /* Offset to beginning of 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);} At this point, I believe that everyone has a deeper understanding of "how to use the fwirte function in C language", so it is advisable to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!