<?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++ Split Problem?!]]></title><description><![CDATA[<p>Ich hab hier eine funktion geschrieben die von updateserver einen string abholt und der dann nach | durchlaufen werden soll und die daraus resultierenden zeichenketten in eine chararry geschrieben werden (~). Aber irg wie gibt er mir die 2. zeichen kette (|) nich aus? könnt ihr mir helfen</p>
<p>Bsp. Zeichenktte vom server &quot;string1<sub>string2</sub>string3<sub>string4|string1</sub>string2~string3|....&quot;</p>
<p>Source:</p>
<pre><code class="language-cpp">void HandleCommand(char* data)
{
	char Command[sizeof(data)];
	strcpy(Command,data);
	char *CommandBuffer[sizeof(data)];
	char *pch;
	int i = 0;

	pch = strtok(Command,&quot;~&quot;);
	while (pch != NULL)
	{
		CommandBuffer[i] = pch;
		pch = strtok (NULL, &quot;~&quot;);
		i++;
	}
	if(!lstrcmp(CommandBuffer[0], &quot;11&quot;))
	{
		MessageBox ( NULL, CommandBuffer[1], &quot;Test&quot;, MB_OK);
	}
}

void StartCommandManagement(char *WebpanelRequest,char *Domain)
{ 
	while (true)
	{
		char *request = HttpRequest(WebpanelRequest,Domain,80);
		char *pch;

		pch = strtok(request,&quot;|&quot;);
		while (pch != NULL)
		{
			if(strstr(pch, &quot;~&quot;)!=0){
				//Start Handle Command
				HandleCommand(pch);
			}
			pch = strtok(NULL, &quot;|&quot;);
		}
		request[0] = '\0';
		break;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/280470/c-split-problem</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 03:07:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/280470.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Jan 2011 12:17:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 12:17:32 GMT]]></title><description><![CDATA[<p>Ich hab hier eine funktion geschrieben die von updateserver einen string abholt und der dann nach | durchlaufen werden soll und die daraus resultierenden zeichenketten in eine chararry geschrieben werden (~). Aber irg wie gibt er mir die 2. zeichen kette (|) nich aus? könnt ihr mir helfen</p>
<p>Bsp. Zeichenktte vom server &quot;string1<sub>string2</sub>string3<sub>string4|string1</sub>string2~string3|....&quot;</p>
<p>Source:</p>
<pre><code class="language-cpp">void HandleCommand(char* data)
{
	char Command[sizeof(data)];
	strcpy(Command,data);
	char *CommandBuffer[sizeof(data)];
	char *pch;
	int i = 0;

	pch = strtok(Command,&quot;~&quot;);
	while (pch != NULL)
	{
		CommandBuffer[i] = pch;
		pch = strtok (NULL, &quot;~&quot;);
		i++;
	}
	if(!lstrcmp(CommandBuffer[0], &quot;11&quot;))
	{
		MessageBox ( NULL, CommandBuffer[1], &quot;Test&quot;, MB_OK);
	}
}

void StartCommandManagement(char *WebpanelRequest,char *Domain)
{ 
	while (true)
	{
		char *request = HttpRequest(WebpanelRequest,Domain,80);
		char *pch;

		pch = strtok(request,&quot;|&quot;);
		while (pch != NULL)
		{
			if(strstr(pch, &quot;~&quot;)!=0){
				//Start Handle Command
				HandleCommand(pch);
			}
			pch = strtok(NULL, &quot;|&quot;);
		}
		request[0] = '\0';
		break;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2007227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007227</guid><dc:creator><![CDATA[spike1993]]></dc:creator><pubDate>Sun, 16 Jan 2011 12:17:32 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 12:42:23 GMT]]></title><description><![CDATA[<p>spike1993 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void HandleCommand(char* data)
{
	char Command[sizeof(data)];
	strcpy(Command,data);
	char *CommandBuffer[sizeof(data)];
</code></pre>
</blockquote>
<p>Auch in deinem reinen C-Code liefert sizeof(data) nicht dir Länge des Arrays! Das kann also nur schief gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007237</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007237</guid><dc:creator><![CDATA[Manni66]]></dc:creator><pubDate>Sun, 16 Jan 2011 12:42:23 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 12:51:15 GMT]]></title><description><![CDATA[<p>das ja wyn kann ja auch 50 oder so reinschreiben aber wo ist der fehler das er immer nur die 1. zeichenkette bearbeitet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007239</guid><dc:creator><![CDATA[spike1993]]></dc:creator><pubDate>Sun, 16 Jan 2011 12:51:15 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 13:12:21 GMT]]></title><description><![CDATA[<p>spike1993 schrieb:</p>
<blockquote>
<p>das ja wyn kann ja auch 50 oder so reinschreiben aber wo ist der fehler das er immer nur die 1. zeichenkette bearbeitet?</p>
</blockquote>
<p>? wyn?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007251</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007251</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Sun, 16 Jan 2011 13:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 13:15:37 GMT]]></title><description><![CDATA[<p>is doch w4yne - mag jemand käse zum wyn?</p>
<p>Nachmal darüber nachdenken was für einen Wert du mit sizeof(char*) erhälst <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="🙂"
    /><br />
Und wieviele Elemente demnach Command und CommandBuffer haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007252</guid><dc:creator><![CDATA[inter2k3]]></dc:creator><pubDate>Sun, 16 Jan 2011 13:15:37 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 13:18:49 GMT]]></title><description><![CDATA[<p>source moddet aber trotzdem ist das problem noch da.</p>
<pre><code class="language-cpp">void HandleCommand(char* data)
{
	char Command[5];
	strcpy(Command,data);
	char *CommandBuffer[5];
	char *pch;
	int i = 0;

	pch = strtok(Command,&quot;~&quot;);
	while (pch != NULL)
	{
		CommandBuffer[i] = pch;
		pch = strtok (NULL, &quot;~&quot;);
		i++;
	}
	if(!lstrcmp(CommandBuffer[0], &quot;11&quot;))
	{
		MessageBox ( NULL, CommandBuffer[1], &quot;Test&quot;, MB_OK);
	}
}

void StartCommandManagement(char *WebpanelRequest,char *Domain)
{ 
	while (true)
	{
		char *request = HttpRequest(WebpanelRequest,Domain,80);
		char *pch;

		pch = strtok(request,&quot;|&quot;);
		while (pch != NULL)
		{
			if(strstr(pch, &quot;~&quot;)!=0){
				//Start Handle Command
				HandleCommand(pch);
			}
			pch = strtok(NULL, &quot;|&quot;);
		}
		request[0] = '\0';
		break;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2007255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007255</guid><dc:creator><![CDATA[spike1993]]></dc:creator><pubDate>Sun, 16 Jan 2011 13:18:49 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 13:41:52 GMT]]></title><description><![CDATA[<p>spike1993 schrieb:</p>
<blockquote>
<p>Bsp. Zeichenktte vom server &quot;string1<sub>string2</sub>string3<sub>string4|string1</sub>string2~string3|....&quot;</p>
</blockquote>
<p>spike1993 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">char Command[5];
    strcpy(Command,data)
</code></pre>
</blockquote>
<p>Du machst deine Buffer viel zu kurz und wunderst dich dann, wenn du dir den Stack zerschießt und merkwürdiges Verhalten rauskriegst? Das mit der Speicherverwaltung solltest du besser noch mal üben. Mit zu wenig Speicher zu arbeiten ist keine Lappalie!</p>
<p>Ansonsten sieht mir der Code eigentlich so aus, als gehöre er mehr ins C- als ins C++-Forum. In C++ ginge das beispielsweise so:</p>
<pre><code class="language-cpp">void HandleCommand(std::string const &amp;data)
{
  std::istringstream tokenizer(data);
  std::string token;
  std::vector&lt;std::string&gt; commands;

  while(std::getline(tokenizer, token, '~')) {
    commands.push_back(token);
  }

  if(commands.size() &gt; 1 &amp;&amp; commands[0] == &quot;11&quot;) {
    MessageBox(NULL, commands[1].c_str(), &quot;Test&quot;, MB_OK);
  }
}

void StartCommandManagement(std::string const &amp;WebpanelRequest, std::string const &amp;Domain)
{
  while (true) {
    std::string request = HttpRequest(WebpanelRequest.c_str(), Domain.c_str(), 80);
    std::istringstream tokenizer(request);
    std::string token;

    while(std::getline(tokenizer, token, '|')) {
      if(token.find('~') != std::string::npos) {
        HandleCommand(token);
      }
    }

    request.clear();
    break;
  }
}
</code></pre>
<p>...und c_str() auch nur, weil mir das nach einem C-API aussieht, um das man nicht herumkommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007266</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sun, 16 Jan 2011 13:41:52 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 14:04:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;
using namespace std;

void HandleCommand(std::string const &amp;data)
{
  istringstream tokenizer(data);
  string token;
  vector&lt;string&gt; commands;

  while(getline(tokenizer, token, '~')) {
    commands.push_back(token);
  }

  if(commands.size() &gt; 1 &amp;&amp; commands[0] == &quot;11&quot;) {
    MessageBox(NULL, commands[1].c_str(), &quot;Test&quot;, MB_OK);
  }
}

void StartCommandManagement(std::string const &amp;WebpanelRequest, std::string const &amp;Domain)
{
  while (true) 
  {
    string request = HttpRequest(WebpanelRequest.c_str(), Domain.c_str(), 80);
    istringstream tokenizer(request);
    string token;

    while(getline(tokenizer, token, '|')) {
      if(token.find('~') != std::string::npos) {
        HandleCommand(token);
      }
    }

    request.clear();
    break;
  }
}
</code></pre>
<p>Fehler:</p>
<pre><code>1&gt;  CommControl.cpp
1&gt;CommControl.cpp(10): error C2079: 'tokenizer' verwendet undefiniertes class 'std::basic_istringstream&lt;_Elem,_Traits,_Alloc&gt;'
1&gt;          with
1&gt;          [
1&gt;              _Elem=char,
1&gt;              _Traits=std::char_traits&lt;char&gt;,
1&gt;              _Alloc=std::allocator&lt;char&gt;
1&gt;          ]
1&gt;CommControl.cpp(10): error C2440: 'Initialisierung': 'const std::string' kann nicht in 'int' konvertiert werden
1&gt;          Kein benutzerdefinierter Konvertierungsoperator verfügbar, der diese Konvertierung durchführen kann, oder der Operator kann nicht aufgerufen werden
1&gt;CommControl.cpp(12): error C2065: 'vector': nichtdeklarierter Bezeichner
1&gt;CommControl.cpp(12): error C2275: 'std::string': Ungültige Verwendung dieses Typs als Ausdruck
1&gt;          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(2063): Siehe Deklaration von 'std::string'
1&gt;CommControl.cpp(12): error C2065: 'commands': nichtdeklarierter Bezeichner
1&gt;CommControl.cpp(14): error C2780: 'std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::getline(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,std::basic_string&lt;_Elem,_Traits,_Alloc&gt; &amp;)': Erwartet 2 Argumente - 3 unterstützt
1&gt;          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(479): Siehe Deklaration von 'std::getline'
1&gt;CommControl.cpp(14): error C2784: &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::getline(std::basic_istream&lt;_Elem,_Traits&gt; &amp;,std::basic_string&lt;_Elem,_Traits,_Alloc&gt; &amp;,const _Elem)&quot;: template-Argument für &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;&quot; konnte nicht von &quot;int&quot; hergeleitet werden.
1&gt;          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(468): Siehe Deklaration von 'std::getline'
1&gt;CommControl.cpp(14): error C2780: 'std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::getline(std::basic_istream&lt;_Elem,_Traits&gt; &amp;&amp;,std::basic_string&lt;_Elem,_Traits,_Alloc&gt; &amp;)': Erwartet 2 Argumente - 3 unterstützt
1&gt;          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(448): Siehe Deklaration von 'std::getline'
1&gt;CommControl.cpp(14): error C2784: &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;std::getline(std::basic_istream&lt;_Elem,_Traits&gt; &amp;&amp;,std::basic_string&lt;_Elem,_Traits,_Alloc&gt; &amp;,const _Elem)&quot;: template-Argument für &quot;std::basic_istream&lt;_Elem,_Traits&gt; &amp;&amp;&quot; konnte nicht von &quot;int&quot; hergeleitet werden.
1&gt;          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(395): Siehe Deklaration von 'std::getline'
1&gt;CommControl.cpp(14): fatal error C1903: Weiterverarbeitung nach vorherigem Fehler nicht möglich; Kompilierung wird abgebrochen.
1&gt;
1&gt;Fehler beim Erstellen
</code></pre>
<p>hab ich irg was vergessen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2007277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007277</guid><dc:creator><![CDATA[spike1993]]></dc:creator><pubDate>Sun, 16 Jan 2011 14:04:46 GMT</pubDate></item><item><title><![CDATA[Reply to c++ Split Problem?! on Sun, 16 Jan 2011 17:53:34 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;sstream&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2007378</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2007378</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sun, 16 Jan 2011 17:53:34 GMT</pubDate></item></channel></rss>