In C how would i write an array to a file

  • Thread starter Thread starter j-lee00
  • Start date Start date
  • Tags Tags
    Array File
Click For Summary
To create, open, and write an array to a text file in C, the functions fopen(), fwrite(), and fread() are essential. When using fopen() on Windows, it is important to include a 'b' in the mode string (e.g., fopen(filename, "wb")) to specify binary mode. This distinction is not necessary on Ubuntu. A recommended resource for understanding C File I/O is the Wikipedia page on fwrite, which provides a comprehensive tutorial. Additionally, some users prefer to create a memory block that contains all data and the file header, allowing them to write the entire block to the hard drive in one operation.
j-lee00
Messages
93
Reaction score
0
In C how would i create, open and write an array to a text file

The array is EeV,

does it make a difference if I am using ubuntu or windows
 
Technology news on Phys.org
fopen() to open the file fwrite() to dump the data fread() to get it back.
The only differenc eon windows is you have to add a 'b' in the fopen() call to specify binary, ie fopen(filename,"wb") to open a file for writing.
 
I like to create a memory block containing all the data and the file header, and then just write the whole block to my hard drive.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K