C language how to read data from one file to memory and then write the data in memory to another file
This article will explain in detail how to read data from one file to memory in c language and then write the data in memory to another file. I think it is very practical, so I will share it for you as a reference. I hope you can get something after reading this article.
Sample code
/ / read data from one file to memory, and then write the data in memory to another file # include "stdafx.h" # include "stdlib.h" int main (int argc, char* argv []) {FILE* fp;FILE* fp2;fp = fopen ("C:/notepad.exe", "rb"); fp2 = fopen ("C:/aa.exe", "wb"); fseek (fp,0,SEEK_END); int size = ftell (fp) Fseek (fp,0,SEEK_SET); unsigned char* buffer = (unsigned char*) malloc (size); fread (buffer,size,1,fp); fwrite (buffer,size,1, fp2); free (buffer); fclose (fp); fclose (fp2); return 0;} / fopen return value: after the file is successfully opened, the file pointer to the stream will be returned. If the file fails to open, return NULL and store the error code in errno. / / fseek int fseek (FILE * stream, long offset, int fromwhere); the function sets the location of the file pointer stream / / the ftell function ftell is used to get the offset bytes of the current position of the file location pointer relative to the beginning of the file. / / fclose uses the fclose () function to output the last remaining data in the buffer to the kernel buffer and release the file pointer and the associated buffer. This is the end of this article on "how to read data from one file to memory in c language and then write the data in memory to another file". I hope the above content can be of some help to you. So that you can learn more knowledge, if you think the article is good, please share it for more people to see.