<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Doubles aus Binärdateien in Textdateien speichern]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich poste hier zum ersten mal, sage deshalb nochmal HALLO, und freue mich auf eine gute Zusammenarbeit.</p>
<p>Zu meinem Problem: ich habe Binärdateien, in denen eine Reihe von double-Werten (Punktkoordinaten) gespeichert sind (sagen wir mal eine 800byte-Datei, also mit 100 doubles). Die Frage ist, wie kann ich diese in ein double-Array einlesen und danach dieses in einer lesbaren Form speichern (txt-file). Im Moment kommen absolute falsche (riesige) Werte raus.</p>
<p>Hier mein (nicht funktionierender) Code:</p>
<pre><code class="language-cpp">FILE * pFile;
double x[50][2]

buffer = (double*) malloc (sizeof(double)*100);

pFile = fopen(&quot;...&quot;, &quot;rb&quot;);

// read file to buffer (8byte-blocks)
result = fread (buffer,8,100,pFile);

for(int i=0;i&lt;50;i++){
  for(int j=0;j&lt;2;j++) x[i][j] = buffer[2*i+j];
}

fclose(pFile);

// save data to textfile
pFile = fopen (&quot;...&quot;,&quot;w&quot;);
for(int i=0;i&lt;50;i++){
  fprintf(pFile,&quot;%f\t%f\n&quot;, x[i][0], x[i][1]);
}

fclose(pFile);
</code></pre>
<p>Würde mich über eine Hilfestellung sehr freuen, habe auch schon mit dem fread() ein bisschen experimentiert, jedoch ohne Erfolg.</p>
<p>Beste Grüße,<br />
ElMuesli.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240277/doubles-aus-binärdateien-in-textdateien-speichern</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 02:20:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240277.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 May 2009 14:51:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 14:51:08 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich poste hier zum ersten mal, sage deshalb nochmal HALLO, und freue mich auf eine gute Zusammenarbeit.</p>
<p>Zu meinem Problem: ich habe Binärdateien, in denen eine Reihe von double-Werten (Punktkoordinaten) gespeichert sind (sagen wir mal eine 800byte-Datei, also mit 100 doubles). Die Frage ist, wie kann ich diese in ein double-Array einlesen und danach dieses in einer lesbaren Form speichern (txt-file). Im Moment kommen absolute falsche (riesige) Werte raus.</p>
<p>Hier mein (nicht funktionierender) Code:</p>
<pre><code class="language-cpp">FILE * pFile;
double x[50][2]

buffer = (double*) malloc (sizeof(double)*100);

pFile = fopen(&quot;...&quot;, &quot;rb&quot;);

// read file to buffer (8byte-blocks)
result = fread (buffer,8,100,pFile);

for(int i=0;i&lt;50;i++){
  for(int j=0;j&lt;2;j++) x[i][j] = buffer[2*i+j];
}

fclose(pFile);

// save data to textfile
pFile = fopen (&quot;...&quot;,&quot;w&quot;);
for(int i=0;i&lt;50;i++){
  fprintf(pFile,&quot;%f\t%f\n&quot;, x[i][0], x[i][1]);
}

fclose(pFile);
</code></pre>
<p>Würde mich über eine Hilfestellung sehr freuen, habe auch schon mit dem fread() ein bisschen experimentiert, jedoch ohne Erfolg.</p>
<p>Beste Grüße,<br />
ElMuesli.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705384</guid><dc:creator><![CDATA[ElMuesli]]></dc:creator><pubDate>Mon, 04 May 2009 14:51:08 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 15:05:50 GMT]]></title><description><![CDATA[<p>falsches Forum?</p>
<p>bist du sicher, dass du in C++ und nicht C programmieren möchtest? Oo</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705400</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 04 May 2009 15:05:50 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 15:11:07 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ich soll es in C oder Fortran machen. In dem Fall dachte ich mir, dass es wohl egal ist, ob C oder C++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705409</guid><dc:creator><![CDATA[ElMuesli]]></dc:creator><pubDate>Mon, 04 May 2009 15:11:07 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 15:13:41 GMT]]></title><description><![CDATA[<p>ElMuesli schrieb:</p>
<blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Ich soll es in C oder Fortran machen. In dem Fall dachte ich mir, dass es wohl egal ist, ob C oder C++.</p>
</blockquote>
<p>Ne, ist es nicht - sonst würden die versch. Unterforen wohl auch keinen Sinn machen...<br />
Also sieh mal zu, dass du es entweder noch mal im C-Forum postest oder wartest, bis dich wer verschiebt...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705412</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 04 May 2009 15:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 15:21:14 GMT]]></title><description><![CDATA[<p>Ok, dann poste ich es nochmal ins C-Forum. Hatte gedacht, dass mein Problem (wahrscheinlich fread oder Pointer/Speicher-Zuweisung) auch hier beantwortet werden könnte.<br />
Gruß und Danke, ElMuesli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705421</guid><dc:creator><![CDATA[ElMuesli]]></dc:creator><pubDate>Mon, 04 May 2009 15:21:14 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 15:34:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::basic_fstream&lt;unsigned char&gt; in(L&quot;values.bin&quot;, std::ios::binary | std::ios::in);
if (in.is_open())
{
	in.seekg(0, std::ios::end);
	std::basic_ifstream&lt;unsigned char&gt;::pos_type len = in.tellg();
	in.seekg(0, std::ios::beg);

	std::wofstream out(L&quot;values.txt&quot;);
	if (out.is_open())
	{
		long count = len / sizeof(double);
		for (long i = 0; i &lt; count; ++i)
		{
			double val = 0.0;
			in.read(reinterpret_cast&lt;unsigned char*&gt;(&amp;val), sizeof(val));
			out &lt;&lt; val &lt;&lt; L&quot;\n&quot;;
		}
		out.close();
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1705430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705430</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Mon, 04 May 2009 15:34:02 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 16:21:20 GMT]]></title><description><![CDATA[<p>Danke dafür... Die Werte sehen damit (von der Formatierung her) schonmal schöner aus. Jedoch können sie nicht stimmen (weiterhin viel zu groß).</p>
<p>Teilweise steht da auch einfach sowas: 1.#QNAN</p>
<p>Die ersten 8 Byte meiner Binärdatei sehen im Hex-Editor so aus: 4036FCEC4004A7DA<br />
Das müsste laut <a href="http://babbage.cs.qc.edu/IEEE-754/64bit.html" rel="nofollow">http://babbage.cs.qc.edu/IEEE-754/64bit.html</a> ein Wert um die 23 sein. Dein (und auch mein) Code speichert -4.98574e+128. Was nun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705453</guid><dc:creator><![CDATA[ElMuesli]]></dc:creator><pubDate>Mon, 04 May 2009 16:21:20 GMT</pubDate></item><item><title><![CDATA[Reply to Doubles aus Binärdateien in Textdateien speichern on Mon, 04 May 2009 22:25:15 GMT]]></title><description><![CDATA[<p>Das Thema hat sich erledigt. Das Problem bestand darin, dass meine binary files offensichtlich auf einer anderen Platform erstellt wurden und noch bearbeitet werden mussten, bevor ich sie auf meinem intel lesen konnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705618</guid><dc:creator><![CDATA[ElMuesli]]></dc:creator><pubDate>Mon, 04 May 2009 22:25:15 GMT</pubDate></item></channel></rss>