<?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[Array als Rückgabewert]]></title><description><![CDATA[<p>hallo,<br />
ich bin ein C++ Neuling and habe ein paar Schwierigkeiten mit Arrays <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> .ich möchte ein bitmap File lesen und die dimensionen (Breite,Höhe) als 2d-Array zurückgeben <a href="http://xn--knnen-jua.In" rel="nofollow">können.In</a> der Funktion ReadHeader sollte man den Pfad,wo sich das Bild befindet als Argument <a href="http://eingeben.So" rel="nofollow">eingeben.So</a> sieht mein Code aus:</p>
<p>[#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;math.h&gt;<br />
#include &lt;fstream&gt;<br />
typedef struct<br />
{<br />
int Size; /* Size of the image <em>/<br />
int res; /</em> reserved zone <em>/<br />
int offset; /</em> address of the beginning of the image <em>/<br />
int info; /</em> size of the zone information <em>/<br />
int width; /</em> Width of the image <em>/<br />
int height ; /</em> Height of the image <em>/<br />
int tim; /</em> Size of the image in bytes <em>/<br />
int Hres; /</em> horizontal resolution <em>/<br />
int Vres; /</em> vertical resolution <em>/<br />
int nbco; /</em> number of colors used <em>/<br />
int impco; /</em> number of important colors */<br />
} bitmap_header;</p>
<p>//ReadHeader sollte B[width][height] zurückgeben</p>
<p>void ReadHeader(char *Titel, int B[][] )<br />
{<br />
FILE *bmp_file;<br />
bitmap_header bmp_header;<br />
char sign[3];</p>
<p>bmp_file=fopen(&quot;Titel.bmp&quot;,&quot;r&quot;);</p>
<p>fgets( sign, sizeof sign , bmp_file);<br />
puts(sign);</p>
<p>/* read the header in only one line */<br />
fread( &amp;bmp_header, sizeof bmp_header, 1, bmp_file );</p>
<p>printf(&quot;width= %d, height= %d\n&quot;, bmp_header.width, bmp_header.height);</p>
<p>fclose(bmp_file);</p>
<p>}<br />
]<br />
Ich kann bis jetzt nur die Dimensionen auf der Konsolen geben.Ich<br />
möchte aber das Bild als Array haben.Hätte Jemand eine Idee <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/206013/array-als-rückgabewert</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 01:00:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/206013.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Feb 2008 13:03:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Array als Rückgabewert on Wed, 20 Feb 2008 13:05:14 GMT]]></title><description><![CDATA[<p>hallo,<br />
ich bin ein C++ Neuling and habe ein paar Schwierigkeiten mit Arrays <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> .ich möchte ein bitmap File lesen und die dimensionen (Breite,Höhe) als 2d-Array zurückgeben <a href="http://xn--knnen-jua.In" rel="nofollow">können.In</a> der Funktion ReadHeader sollte man den Pfad,wo sich das Bild befindet als Argument <a href="http://eingeben.So" rel="nofollow">eingeben.So</a> sieht mein Code aus:</p>
<p>[#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;math.h&gt;<br />
#include &lt;fstream&gt;<br />
typedef struct<br />
{<br />
int Size; /* Size of the image <em>/<br />
int res; /</em> reserved zone <em>/<br />
int offset; /</em> address of the beginning of the image <em>/<br />
int info; /</em> size of the zone information <em>/<br />
int width; /</em> Width of the image <em>/<br />
int height ; /</em> Height of the image <em>/<br />
int tim; /</em> Size of the image in bytes <em>/<br />
int Hres; /</em> horizontal resolution <em>/<br />
int Vres; /</em> vertical resolution <em>/<br />
int nbco; /</em> number of colors used <em>/<br />
int impco; /</em> number of important colors */<br />
} bitmap_header;</p>
<p>//ReadHeader sollte B[width][height] zurückgeben</p>
<p>void ReadHeader(char *Titel, int B[][] )<br />
{<br />
FILE *bmp_file;<br />
bitmap_header bmp_header;<br />
char sign[3];</p>
<p>bmp_file=fopen(&quot;Titel.bmp&quot;,&quot;r&quot;);</p>
<p>fgets( sign, sizeof sign , bmp_file);<br />
puts(sign);</p>
<p>/* read the header in only one line */<br />
fread( &amp;bmp_header, sizeof bmp_header, 1, bmp_file );</p>
<p>printf(&quot;width= %d, height= %d\n&quot;, bmp_header.width, bmp_header.height);</p>
<p>fclose(bmp_file);</p>
<p>}<br />
]<br />
Ich kann bis jetzt nur die Dimensionen auf der Konsolen geben.Ich<br />
möchte aber das Bild als Array haben.Hätte Jemand eine Idee <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1459405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1459405</guid><dc:creator><![CDATA[noname82]]></dc:creator><pubDate>Wed, 20 Feb 2008 13:05:14 GMT</pubDate></item><item><title><![CDATA[Reply to Array als Rückgabewert on Wed, 20 Feb 2008 13:32:19 GMT]]></title><description><![CDATA[<p>Aufräumen!</p>
<pre><code class="language-cpp">#include &lt;utility&gt; // std::pair, std::make_pair
#include &lt;cstring&gt; // std::strcmp
#include &lt;fstream&gt;

struct bitmap_header_t
{
    int Size; /* Size of the image */
    int res; /* reserved zone */
    int offset; /* address of the beginning of the image */
    int info; /* size of the zone information */
    int width; /* Width of the image */
    int height ; /* Height of the image */
    int tim; /* Size of the image in bytes */
    int Hres; /* horizontal resolution */
    int Vres; /* vertical resolution */
    int nbco; /* number of colors used */
    int impco; /* number of important colors */
};

std::pair&lt;int, int&gt; read_header(const char* file_name, bitmap_header_t&amp; dest)
{
    std::ifstream file_stream(file_name, std::ios_base::binary);

    char sign[4] = { 0 };
    file_stream.read(sign, sizeof(char) * 3);

    if (std::strcmp(&quot;BMP&quot;, sign) != 0) throw std::invalid_argument(&quot;invalid format&quot;);

    file_stream.read(reinterpret_cast&lt;char*&gt;(&amp;dest), sizeof(bitmap_header_t));

    return std::make_pair(dest.width, dest.height);
}
</code></pre>
<p>Wobei die Bitmap-Header-Struktur falsch ist!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1459444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1459444</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 20 Feb 2008 13:32:19 GMT</pubDate></item><item><title><![CDATA[Reply to Array als Rückgabewert on Wed, 20 Feb 2008 14:01:34 GMT]]></title><description><![CDATA[<p>Das nennt man eine prompte Antwort <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
warum sollte die Bitmap-Header-Struktur falsch sein? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>ich muss gestehen, dass ich die folgenden Zeilen nicht versteht:</p>
<pre><code class="language-cpp">std::ifstream file_stream(file_name, std::ios_base::binary);

    char sign[4] = { 0 };
    file_stream.read(sign, sizeof(char) * 3);

    if (std::strcmp(&quot;BMP&quot;, sign) != 0) throw std::invalid_argument(&quot;invalid format&quot;);

    file_stream.read(reinterpret_cast&lt;char*&gt;(&amp;dest), sizeof(bitmap_header_t));
</code></pre>
<p>Könntest Du Sie mir bitte erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1459469</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1459469</guid><dc:creator><![CDATA[noname82]]></dc:creator><pubDate>Wed, 20 Feb 2008 14:01:34 GMT</pubDate></item><item><title><![CDATA[Reply to Array als Rückgabewert on Wed, 20 Feb 2008 14:18:56 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::ifstream file_stream(file_name, std::ios_base::binary); // Datei zum binären Lesen öffnen

char sign[4] = { 0 }; // einen String aufn Stack und mit 0 initialisieren. Wichtig ist, dass sign[ 3 ] = 0.
file_stream.read(sign, sizeof(char) * 3); // Die ersten 3 Bytes nach sign lesen.

if( std::strcmp( &quot;BMP&quot;, sign ) != 0 ) // Gucken, ob die ersten 3 Bytes BMP sind.
    throw std::invalid_argument( &quot;invalid format&quot; ); // sonst eine exception schmeißen

file_stream.read(reinterpret_cast&lt;char*&gt;( &amp;dest ), sizeof( bitmap_header_t ) ); // dann den restlichen Header lesen.
</code></pre>
<p>greetz, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1459485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1459485</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Wed, 20 Feb 2008 14:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to Array als Rückgabewert on Wed, 20 Feb 2008 14:36:13 GMT]]></title><description><![CDATA[<p>danke schön.jetzt verstehe ich viel besser <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /><br />
ich bekomme beim Kompilieren (VC++ 6.0) der folgenden Zeile:</p>
<pre><code class="language-cpp">if( std::strcmp( &quot;BMP&quot;, sign ) != 0 )
</code></pre>
<p>die folgende Fehlermeldung:<br />
C:\VisualC\...\Test.cpp(27) : error C2039: 'strcmp' : Ist kein Element von 'std'<br />
beim Weglassen von 'std' habe ich noch mehr Fehler.....<br />
Ach ja,ich benutze WinXP und VC ++ 6.0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1459494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1459494</guid><dc:creator><![CDATA[noname82]]></dc:creator><pubDate>Wed, 20 Feb 2008 14:36:13 GMT</pubDate></item></channel></rss>