<?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[c++ typedef Array]]></title><description><![CDATA[<p>Hallo zusammen, ich möchte ein char 2d. Array mit Werten füllen allerdings funktioniert es nicht.</p>
<pre><code>typedef struct retval {
		char** arrayRef;
		int zeile; 
		int spalte;
	}RETVAL;
		// Gibt ein 2D-Array in der Struktur zurück
	__declspec(dllexport) RETVAL* __stdcall get2darray()
	{
		retval test;
		test.arrayRef = (char**) new const char*[2][2];
		test.arrayRef[1][1] = &quot;test&quot;;//funktioniert leider nicht
		test.count=1;
		test.lLen = 1;
		return &amp;test;
	}
</code></pre>
<p>So test.arrayRef[1][1] = &quot;test&quot;; müsste es doch funktionieren. Oder habe ich hier ein Denkfehler <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/318550/c-typedef-array</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Jul 2026 08:56:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318550.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Jul 2013 10:04:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:04:17 GMT]]></title><description><![CDATA[<p>Hallo zusammen, ich möchte ein char 2d. Array mit Werten füllen allerdings funktioniert es nicht.</p>
<pre><code>typedef struct retval {
		char** arrayRef;
		int zeile; 
		int spalte;
	}RETVAL;
		// Gibt ein 2D-Array in der Struktur zurück
	__declspec(dllexport) RETVAL* __stdcall get2darray()
	{
		retval test;
		test.arrayRef = (char**) new const char*[2][2];
		test.arrayRef[1][1] = &quot;test&quot;;//funktioniert leider nicht
		test.count=1;
		test.lLen = 1;
		return &amp;test;
	}
</code></pre>
<p>So test.arrayRef[1][1] = &quot;test&quot;; müsste es doch funktionieren. Oder habe ich hier ein Denkfehler <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2339400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339400</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:12:35 GMT]]></title><description><![CDATA[<p>Was soll denn das bitteschoen werden?<br />
Willst du jetzt ein 2d-Char-Area oder ein 2d-Char*-Area? Allgemein sieht mir dein Loesungsansatz eher nach C mit new aus. Warum keinen Vector <a href="http://o.ae" rel="nofollow">o.ae</a>.?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339402</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:12:35 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:15:39 GMT]]></title><description><![CDATA[<p>Es ist ein Dll und ich kann leider da kein vektor verwenden, da ich das Ergebnis in <a href="http://VB.Net" rel="nofollow">VB.Net</a> noch benutzen möchte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339403</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:15:39 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:18:26 GMT]]></title><description><![CDATA[<p>Irgendwie kommt mir das trotzdem spanisch vor. Willst du jetzt n*n Chars oder n*n C-Strings?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339405</guid><dc:creator><![CDATA[Jonas OSDever]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:18:26 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:22:23 GMT]]></title><description><![CDATA[<p>Ich möchte ein 2d Strin Array, die ich mit Werten aus einer DB Abfrage füllen möchte (Es sollen nicht einzelen Buchstaben sondern Wörter gespeichert werden)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339406</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:22:23 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:22:39 GMT]]></title><description><![CDATA[<p>Du kannst mittels std::vector::data() oder &amp;std::vector[0] and den internen char buffer gelangen. Bei mir hat sich eingebuergert, einen linearen Buffer zu allokieren und die konkrete 2D-Position an mittels width und height auszurechnen.</p>
<pre><code class="language-cpp">test.arrayRef[1][1] = &quot;test&quot;;
</code></pre>
<p>Nein, das funktioniert nicht. Jede eckiges Klammerpaar nimmt die ein * . D.h. aus char** mit [][] wird char. Du kannst keinen char* (&quot;test&quot;, c-String) einem char zuweisen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339407</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:22:39 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:30:44 GMT]]></title><description><![CDATA[<pre><code>Nein, das funktioniert nicht. Jede eckiges Klammerpaar nimmt die ein * . D.h. aus char** mit [][] wird char. Du kannst keinen char* (&quot;test&quot;, c-String) einem char zuweisen.
</code></pre>
<p>und wie soll ich es dann machen. Mein Ziel ist es ein 2d Array in dem Werte stehen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339408</guid><dc:creator><![CDATA[borhan]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:30:44 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 10:34:34 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">test.arrayRef = (char**) new const char*[2][2];
</code></pre>
<p>wird dich auch nicht glücklich machen.</p>
<p>Das Ergebnis des new ist ein const char*(<em>)[2]. Also ein Zeiger auf ein Array (aus const char</em>), kein Zeiger auf einen Zeiger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339410</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 17 Jul 2013 10:34:34 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 11:08:30 GMT]]></title><description><![CDATA[<p>Bin ich der einzige, den es stört, dass er...<br />
...in einer Funktion sowohl den Struktur- als auch den umdefinierten Namen verwendet, also beides mischt?<br />
...in nicht existente Felder (<strong>count</strong>,<strong>lLen</strong>) schreiben möchte?<br />
...die Referenz lokalen Speichers zurückgibt?<br />
Um nur ein paar Dinge zu nennen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2339413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339413</guid><dc:creator><![CDATA[Youka]]></dc:creator><pubDate>Wed, 17 Jul 2013 11:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to c++ typedef Array on Wed, 17 Jul 2013 11:08:42 GMT]]></title><description><![CDATA[<p>Meint der TE so etwas?<br />
test.h:</p>
<pre><code>#ifndef TEST_H
#define TEST_H

#ifdef __cplusplus
extern &quot;C&quot;{
#endif

  typedef struct 
  {
    int argc;
    char **argv;
  } c_style_handle;

  c_style_handle new_handle();

  void get2darray(c_style_handle *h);

  void free_handle(c_style_handle *h);

#ifdef __cplusplus
}
#endif

#endif
</code></pre>
<p>test.cpp:</p>
<pre><code>#include &lt;cstring&gt;
#include &quot;test.h&quot;

c_style_handle new_handle()
{
  c_style_handle h;
  h.argc = 0;
  h.argv = 0;
  return h;
}

void get2darray(c_style_handle *h)
{
  if (h-&gt;argc)
    {
      free_handle(h);
    }
  h-&gt;argc = 3;
  h-&gt;argv = new char*[4];
  h-&gt;argv[0] = new char[6];
  std::strcpy(h-&gt;argv[0], &quot;Hello&quot;);
  h-&gt;argv[1] = new char[6];
  std::strcpy(h-&gt;argv[1], &quot;World&quot;);
  h-&gt;argv[2] = new char[2];
  std::strcpy(h-&gt;argv[2], &quot;!&quot;);
  h-&gt;argv[3] = 0;
}

void free_handle(c_style_handle *h)
{
  if (h-&gt;argc)
    {
      for (int i = 0; i &lt; h-&gt;argc; ++i)
        delete[] h-&gt;argv[i];
      delete[] h-&gt;argv;
      h-&gt;argc = 0;
    }
}
</code></pre>
<p>test.c (hier C99, aber das ist nicht essentiell):</p>
<pre><code>#include &lt;stdio.h&gt;
#include &quot;test.h&quot;

int main()
{
  c_style_handle h = new_handle();

  get2darray(&amp;h);
  for (int i = 0; i &lt; h.argc; ++i)
    {
      fputs(h.argv[i], stdout);
      putchar(' ');
    }

  free_handle(&amp;h);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2339414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2339414</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 17 Jul 2013 11:08:42 GMT</pubDate></item></channel></rss>