<?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[CharArrays - Verständnissproblem ?]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich hab hier was mit 2 char arrays was mich bekloppt macht.</p>
<p>also beide sind public member einer klasse:</p>
<pre><code>...
char   input[BUFFER_SIZE];
char   message[BUFFER_SIZE];
...
</code></pre>
<p>das input array wird so befüllt:</p>
<pre><code>this-&gt;in_bytes = recv( this-&gt;socket_id, this-&gt;input, sizeof( this-&gt;input ) - 1 , 0 );
</code></pre>
<p>das message array fülle ich in einer schleife mit ein par bedingungen dann so:</p>
<pre><code>this-&gt;message[b+lastInt] = this-&gt;input[b];
</code></pre>
<p>wenn ich nun danach beide ausgeben will, klappt das nur mit dem input array, beim message array bekomme ich keine ausgabe:</p>
<pre><code>printf(&quot;\n\n Input 2: %s  \n&quot; , this-&gt;input );
printf(&quot;\n Message 2: %s  &quot; , this-&gt;message );
</code></pre>
<p>wenn ich aber :</p>
<pre><code>printf(&quot;\n Message test: %c  &quot; , this-&gt;message[4] );
</code></pre>
<p>schreibe , oder nen forloop drüber mache steht da alles drin ... auch ein strcpy() klappt nur beim input und nicht beim massage ....<br />
kann mir das bitte einer erklähren ?</p>
<p>vilen dank schonmal</p>
<p>uwi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/308779/chararrays-verständnissproblem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 17:13:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/308779.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Oct 2012 11:24:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 11:24:10 GMT]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich hab hier was mit 2 char arrays was mich bekloppt macht.</p>
<p>also beide sind public member einer klasse:</p>
<pre><code>...
char   input[BUFFER_SIZE];
char   message[BUFFER_SIZE];
...
</code></pre>
<p>das input array wird so befüllt:</p>
<pre><code>this-&gt;in_bytes = recv( this-&gt;socket_id, this-&gt;input, sizeof( this-&gt;input ) - 1 , 0 );
</code></pre>
<p>das message array fülle ich in einer schleife mit ein par bedingungen dann so:</p>
<pre><code>this-&gt;message[b+lastInt] = this-&gt;input[b];
</code></pre>
<p>wenn ich nun danach beide ausgeben will, klappt das nur mit dem input array, beim message array bekomme ich keine ausgabe:</p>
<pre><code>printf(&quot;\n\n Input 2: %s  \n&quot; , this-&gt;input );
printf(&quot;\n Message 2: %s  &quot; , this-&gt;message );
</code></pre>
<p>wenn ich aber :</p>
<pre><code>printf(&quot;\n Message test: %c  &quot; , this-&gt;message[4] );
</code></pre>
<p>schreibe , oder nen forloop drüber mache steht da alles drin ... auch ein strcpy() klappt nur beim input und nicht beim massage ....<br />
kann mir das bitte einer erklähren ?</p>
<p>vilen dank schonmal</p>
<p>uwi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257300</guid><dc:creator><![CDATA[uwi2k2]]></dc:creator><pubDate>Fri, 05 Oct 2012 11:24:10 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 11:30:55 GMT]]></title><description><![CDATA[<p>Vielleicht nicht nullterminiert?</p>
<p>&lt;<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    />&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257301</guid><dc:creator><![CDATA[glühbirne]]></dc:creator><pubDate>Fri, 05 Oct 2012 11:30:55 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 11:51:12 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>doch das ist bei beiden der fall,</p>
<p>aber ich habe gerade festgestellt das message wohl nur auf den speicher von input verweisst...<br />
wenn:</p>
<pre><code>eins[3] = 'a';
zewi[3] = 'b';

eins[3] = zewi[3];
</code></pre>
<p>was steht dann in eins[3] .. doch b oder nicht ...<br />
hab ich denn heute so nen brett vorm kopf ?</p>
<p>uwi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257307</guid><dc:creator><![CDATA[uwi2k2]]></dc:creator><pubDate>Fri, 05 Oct 2012 11:51:12 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 12:02:41 GMT]]></title><description><![CDATA[<p>uwi2k2 schrieb:</p>
<blockquote>
<p>aber ich habe gerade festgestellt das message wohl nur auf den speicher von input verweisst...</p>
</blockquote>
<p>Das kann nicht sein; denn message ist weder ein Zeiger noch eine Referenz.</p>
<p>Aus dem, was du hier gezeigt hast, geht nicht wirklich vor, was du genau machst. Da geht noch was. Ansonnsten ist es ein Ratespiel und auf Raten hat hier kaum einer Lust.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257311</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Fri, 05 Oct 2012 12:02:41 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 12:09:26 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich weiß nicht wie deine Schleife genau aussieht und was lastInt ist, aber du weist dem message die Werte von input - versetzt um lastInt - zu. Von da her gibt es da keinen Verweis. Warum du keine Ausgabe bekommst, kann ich ohne weiteren Code nicht sagen. Aber es könnte schon mal problematisch sein, wenn du anfängst, die Werte von message erst an der lastInt-ten Stelle zu füllen, dann aber bei der Ausgabe gleich mit dem ersten Array-Element anfängst, dieses aber nicht definiert sind.</p>
<p>uwi2k2 schrieb:</p>
<blockquote>
<p>wenn:</p>
<pre><code>eins[3] = 'a';
zewi[3] = 'b';

eins[3] = zewi[3];
</code></pre>
<p>was steht dann in eins[3] .. doch b oder nicht ...</p>
</blockquote>
<p>Natürlich b.</p>
<p>uwi2k2 schrieb:</p>
<blockquote>
<p>hab ich denn heute so nen brett vorm kopf ?</p>
</blockquote>
<p>Anscheinend <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257315</guid><dc:creator><![CDATA[*Rewind*]]></dc:creator><pubDate>Fri, 05 Oct 2012 12:09:26 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 12:10:49 GMT]]></title><description><![CDATA[<p>hi ok,</p>
<p>hier mal die 2 funktionen um die es geht:</p>
<pre><code>int Socket_Client::read( )
{           	
    this-&gt;cleanInput();
    this-&gt;in_bytes = recv( this-&gt;socket_id, this-&gt;input, sizeof( this-&gt;input ) - 1 , 0 );

    if( this-&gt;in_bytes == -1)
        return -1;

    this-&gt;input[this-&gt;in_bytes] = '\0';

    this-&gt;SplitData();

    return 0;      
};
</code></pre>
<p>...</p>
<pre><code>void Socket_Client::SplitData()
{
	this-&gt;process = false;
	memset( &amp;this-&gt;message[0], 0, sizeof( this-&gt;message ) );
	bool umschalter = false;
	int  umschaltInt = 0;
	int  lastInt = 0;

        printf(&quot;\n\n Input 1: %s  \n&quot; , this-&gt;input );

	printf(&quot;\n Holder 1: %s  \n&quot; , this-&gt;holder );

    for( int a = 0; a &lt; sizeof( this-&gt;holder); a++ )  
	   {
          if( this-&gt;holder[a] != NULL )
		    {    
				if( this-&gt;holder[a] == this-&gt;trennzeichen )
				  {
                    umschalter = true;
                    umschaltInt = a;
					printf(&quot;\n Trennzeichen: ++%c++ &quot; , this-&gt;holder[a] );
				  }
				else
				 {
					lastInt = a;
                    if( umschalter )
					  {
						  this-&gt;holder[a-umschaltInt] = this-&gt;holder[a];
						  this-&gt;holder[a] = 0;
					  }
					else
                       this-&gt;message[a] = this-&gt;holder[a];
				 }
		    }
    	}

	printf(&quot;\n Message:%s-- &quot; , this-&gt;message );
	printf(&quot;\n Holder 2:%s-- &quot; , this-&gt;holder );

    lastInt++;

	printf(&quot;\n\n Input 2: %s  \n&quot; , this-&gt;input );

    // neuen input verarbeiten
    for( int b = 0; b &lt; sizeof( this-&gt;input)-2; b++ )  
	   {

          if( this-&gt;input[b] != NULL )
		    {
             //printf(&quot; *%c* &quot; , this-&gt;input[b] );

             if( !umschalter )
			   {
				if( this-&gt;input[b] == this-&gt;trennzeichen )
				  {
                    umschalter = true;
					this-&gt;message[b+lastInt]   = ';';
					this-&gt;message[b+lastInt+1] = '\0';
					printf(&quot; trennzeichen &quot; );
				  }
				else
				 {
					 cout &lt;&lt; endl;
					 cout &lt;&lt; endl;
					 cout &lt;&lt; &quot;i:&quot; &lt;&lt; this-&gt;input[b] &lt;&lt; endl;
					 cout &lt;&lt; &quot;r:&quot; &lt;&lt; &amp;this-&gt;input[b] &lt;&lt; endl;
                     //this-&gt;message[b+lastInt] = this-&gt;input[b] ;
					 memcpy ( &amp;this-&gt;message[b+lastInt] , &amp;this-&gt;input[b] , 1 );
					 cout &lt;&lt; &quot;m:&quot; &lt;&lt; this-&gt;message[b+lastInt] &lt;&lt; endl;
					//printf(&quot; - setze: %i : %c &quot; , ( b+lastInt ) , this-&gt;input[b] );
					//printf(&quot; %c &quot; ,  this-&gt;message[( b+lastInt )] );
				 }
			   }
			 else
			   {
			      this-&gt;holder[b+lastInt-umschaltInt] = this-&gt;input[b];
			   }

		    } 
    	}

	printf(&quot;\n Message 2: %s -- &quot; , this-&gt;message );
	printf(&quot;\n Holder 3: %s -- \n&quot; , this-&gt;holder );  

    this-&gt;cleanInput();

	string tester(this-&gt;message);

	printf(&quot;\n Message 3: %s -- &quot; , tester );

}
</code></pre>
<p>ich hoffe das hilft weiter</p>
<p>danke !<br />
uwi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257317</guid><dc:creator><![CDATA[uwi2k2]]></dc:creator><pubDate>Fri, 05 Oct 2012 12:10:49 GMT</pubDate></item><item><title><![CDATA[Reply to CharArrays - Verständnissproblem ? on Fri, 05 Oct 2012 12:16:41 GMT]]></title><description><![CDATA[<p>aahh ,</p>
<p>danke @[Rewind]</p>
<p>das wars ... da ich in massage immer mit 1 angefangen habe war das 0te element immer nicht gesetzt ... DANKE !!!<br />
das hat mich wieder 2 stunden meines lebens gekostet so ein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> Fehler ..</p>
<p>Danke !!<br />
uwi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2257319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2257319</guid><dc:creator><![CDATA[uwi2k2]]></dc:creator><pubDate>Fri, 05 Oct 2012 12:16:41 GMT</pubDate></item></channel></rss>