Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C language how to read data from one file to memory and then write the data in memory to another file

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report