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

Discussion Overview

The discussion focuses on how to create, open, and write an array to a text file in the C programming language. It includes considerations for file handling on different operating systems, specifically Ubuntu and Windows.

Discussion Character

  • Technical explanation, Homework-related

Main Points Raised

  • One participant asks about the process of creating, opening, and writing an array to a text file in C, specifically mentioning an array named EeV[i] and inquiring about differences between Ubuntu and Windows.
  • Another participant suggests using fopen() to open the file and fwrite() to write the data, noting that on Windows, a 'b' must be added to the fopen() call to specify binary mode.
  • A third participant references a Wikipedia page as a good tutorial on C File I/O and mentions that a Google search yields many results on the topic.
  • Another participant proposes creating a memory block that contains all the data along with the file header, suggesting this as a method to write the entire block to the hard drive.

Areas of Agreement / Disagreement

Participants present various methods and considerations for writing an array to a file, but there is no consensus on a single approach or resolution of the initial question.

Contextual Notes

There may be limitations regarding the specifics of the array data type, the structure of the file header, and the handling of different operating systems that are not fully addressed in the discussion.

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.
 

Similar threads

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