Skip to content

Commit

Permalink
read and write in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Sep 25, 2024
1 parent 64c82fa commit 91a8981
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void OverwriteNodeSection(const char *filename, int fpos,
const NDArray<const double, 2> coord_arr) {

// Open the file with read and write permissions
FILE *fp = fopen(filename, "r+b");
FILE *fp = fopen(filename, "rb+");
if (!fp) {
throw std::runtime_error("Cannot open file for reading and writing.");
}
Expand Down Expand Up @@ -957,10 +957,7 @@ void OverwriteNodeSection(const char *filename, int fpos,

// Seek back to the beginning of the line and write the updated line
fseek(fp, line_start_pos, SEEK_SET);
if (fwrite(line, 1, line_length, fp) != line_length) {
fclose(fp);
throw std::runtime_error("Failed to write modified line to file.");
}
fwrite(line, 1, line_length, fp);

// Move to the next node
node_idx++;
Expand Down

0 comments on commit 91a8981

Please sign in to comment.