Note that there are some explanatory texts on larger screens.

plurals
  1. POstdio data from write not making it into a file
    primarykey
    data
    text
    <p>I'm having a problem with using stdio commands for manipulating data in a file. I short, when I write data into a file, write returns an int indicating that it was successful, but when I read it back out I only get the old data.</p> <p>Here's a stripped down version of the code:</p> <pre><code>fd = open(filename,O_RDWR|O_APPEND); struct dE *cDE = malloc(sizeof(struct dE)); //Read present data printf("\nreading values at %d\n",off); printf("SeekStatus &lt;%d&gt;\n",lseek(fd,off,SEEK_SET)); printf("ReadStatus &lt;%d&gt;\n",read(fd,cDE,deSize)); printf("current Key/Data &lt;%d/%s&gt;\n",cDE-&gt;key,cDE-&gt;data); printf("\nwriting new values\n"); //Change the values locally cDE-&gt;key = //something new cDE-&gt;data = //something new //Write them back printf("SeekStatus &lt;%d&gt;\n",lseek(fd,off,SEEK_SET)); printf("WriteStatus &lt;%d&gt;\n",write(fd,cDE,deSize)); //Re-read to make sure that it got written back printf("\nre-reading values at %d\n",off); printf("SeekStatus &lt;%d&gt;\n",lseek(fd,off,SEEK_SET)); printf("ReadStatus &lt;%d&gt;\n",read(fd,cDE,deSize)); printf("current Key/Data &lt;%d/%s&gt;\n",cDE-&gt;key,cDE-&gt;data); </code></pre> <p>Furthermore, here's the dE struct in case you're wondering:</p> <pre><code>struct dE { int key; char data[DataSize]; }; </code></pre> <p>This prints:</p> <pre><code>reading values at 1072 SeekStatus &lt;1072&gt; ReadStatus &lt;32&gt; current Key/Data &lt;27/old&gt; writing new values SeekStatus &lt;1072&gt; WriteStatus &lt;32&gt; re-reading values at 1072 SeekStatus &lt;1072&gt; ReadStatus &lt;32&gt; current Key/Data &lt;27/old&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload