<?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[2 char-Elemente in 1]]></title><description><![CDATA[<p>tach-chen......</p>
<p>und zwar häng ich an folgenden problem. ich habe nen char string der 12 zeichen groß ist. alle elemente sind zahlen. jetzt will ich immer zwei elemente in eins packen, so dass am ende ein neues array mit nicht mehr 12 elementen da ist, sondern nur noch mit 6. sprich ungefähr so: 0|2|3|4|4|8|1|0|2|6|2|3 soll am ende so aussehen 02|34|48|10|26|23</p>
<p>die striche stehen jetzt mal für die einzelnen elemente...</p>
<p>am besten wäre es noch, wenn man das gleich in int konvertieren könnte, muss aber nicht sein.</p>
<p>hier mal mein quelltext, in dem ich das benötige:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

using namespace std;

int main(int argc, char *argv[])
{
	// Eingabe Lottozahlen
	/*
	char ziehung[12];
	cout&lt;&lt;&quot;Eingabe Lottozahlen:&quot;&lt;&lt;endl;
	for(int b=0; b&lt;12; b++)
	{
		cin &gt;&gt;ziehung[b];
	}
	*/

    char     filename[128]=&quot;lotto.txt&quot;;
    ifstream file;
    char     zeile[1024];
	string   lzeilen[12];

    // Datei öffnen
    file.open(filename, ios::in);

    if (file.good())
    {
        file.seekg(0L, ios::beg);

        for (int i=0;! file.eof();i++)
        {	
			file.getline(zeile, 1024);
			lzeilen[i]=zeile;
        }
    }
    else
    {
        cout &lt;&lt; &quot;Datei nicht gefunden.&quot; &lt;&lt; endl;
    }

	char charArray[17][12];
	char tmpcharArray[12][12];
	char neucharArray[6][12];

	// String in 2 dim char-Array konvertieren
	for(int j=0; j&lt;12; j++)
	{
		strcpy(charArray[j],lzeilen[j].c_str());
	}

	// Leerzeichen entfernen
	for(j=0; j&lt;12; j++)
	{
		for(int z=0, a=0; z&lt;17; z++)
		{
			if(charArray[j][z] == ' ')
			{
			}
			else
			{
				tmpcharArray[j][a]=charArray[j][z];
				a++;
			}
		}
	}

	// Ausgabe
	cout&lt;&lt;endl&lt;&lt;endl;

	for(j=0; j&lt;12; j++)
	{
		for(int z=0; z&lt;12; z++)
		{
			cout&lt;&lt;tmpcharArray[j][z];
		}
		cout&lt;&lt;endl;
	}
	cout&lt;&lt;endl;

    return 0;
}

/*
steht in der lotto.txt:

11 15 25 37 38 47
11 16 20 26 29 45
03 18 20 30 46 49
02 12 15 25 31 49
01 03 05 07 41 48
01 13 14 26 31 45
02 07 09 11 20 27
02 12 16 20 27 28
07 18 21 22 44 45
06 07 29 33 36 44
01 12 22 33 39 40
01 07 08 34 37 41
*/
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/159536/2-char-elemente-in-1</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 14:51:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/159536.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Sep 2006 10:37:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 2 char-Elemente in 1 on Sat, 16 Sep 2006 10:37:04 GMT]]></title><description><![CDATA[<p>tach-chen......</p>
<p>und zwar häng ich an folgenden problem. ich habe nen char string der 12 zeichen groß ist. alle elemente sind zahlen. jetzt will ich immer zwei elemente in eins packen, so dass am ende ein neues array mit nicht mehr 12 elementen da ist, sondern nur noch mit 6. sprich ungefähr so: 0|2|3|4|4|8|1|0|2|6|2|3 soll am ende so aussehen 02|34|48|10|26|23</p>
<p>die striche stehen jetzt mal für die einzelnen elemente...</p>
<p>am besten wäre es noch, wenn man das gleich in int konvertieren könnte, muss aber nicht sein.</p>
<p>hier mal mein quelltext, in dem ich das benötige:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

using namespace std;

int main(int argc, char *argv[])
{
	// Eingabe Lottozahlen
	/*
	char ziehung[12];
	cout&lt;&lt;&quot;Eingabe Lottozahlen:&quot;&lt;&lt;endl;
	for(int b=0; b&lt;12; b++)
	{
		cin &gt;&gt;ziehung[b];
	}
	*/

    char     filename[128]=&quot;lotto.txt&quot;;
    ifstream file;
    char     zeile[1024];
	string   lzeilen[12];

    // Datei öffnen
    file.open(filename, ios::in);

    if (file.good())
    {
        file.seekg(0L, ios::beg);

        for (int i=0;! file.eof();i++)
        {	
			file.getline(zeile, 1024);
			lzeilen[i]=zeile;
        }
    }
    else
    {
        cout &lt;&lt; &quot;Datei nicht gefunden.&quot; &lt;&lt; endl;
    }

	char charArray[17][12];
	char tmpcharArray[12][12];
	char neucharArray[6][12];

	// String in 2 dim char-Array konvertieren
	for(int j=0; j&lt;12; j++)
	{
		strcpy(charArray[j],lzeilen[j].c_str());
	}

	// Leerzeichen entfernen
	for(j=0; j&lt;12; j++)
	{
		for(int z=0, a=0; z&lt;17; z++)
		{
			if(charArray[j][z] == ' ')
			{
			}
			else
			{
				tmpcharArray[j][a]=charArray[j][z];
				a++;
			}
		}
	}

	// Ausgabe
	cout&lt;&lt;endl&lt;&lt;endl;

	for(j=0; j&lt;12; j++)
	{
		for(int z=0; z&lt;12; z++)
		{
			cout&lt;&lt;tmpcharArray[j][z];
		}
		cout&lt;&lt;endl;
	}
	cout&lt;&lt;endl;

    return 0;
}

/*
steht in der lotto.txt:

11 15 25 37 38 47
11 16 20 26 29 45
03 18 20 30 46 49
02 12 15 25 31 49
01 03 05 07 41 48
01 13 14 26 31 45
02 07 09 11 20 27
02 12 16 20 27 28
07 18 21 22 44 45
06 07 29 33 36 44
01 12 22 33 39 40
01 07 08 34 37 41
*/
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1138380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1138380</guid><dc:creator><![CDATA[MW_ICEMAN]]></dc:creator><pubDate>Sat, 16 Sep 2006 10:37:04 GMT</pubDate></item><item><title><![CDATA[Reply to 2 char-Elemente in 1 on Sat, 16 Sep 2006 12:00:49 GMT]]></title><description><![CDATA[<p>Ein char kann doch nur ein Zeichen speichern!<br />
Was du machen kannst, ist 2 chars in einen short o.Ä zu schreiben, ungefähr so:</p>
<pre><code class="language-cpp">char c[2] = {'a', 'b'};
short s = (c[0] &lt;&lt; 8) + (c[1]);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1138434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1138434</guid><dc:creator><![CDATA[qasdfgh]]></dc:creator><pubDate>Sat, 16 Sep 2006 12:00:49 GMT</pubDate></item></channel></rss>