<?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[Newbee - strncat und Speicher]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade eine CSV-Datei zu schreiben folgender Aufbau:<br />
&quot;eins&quot;;&quot;zwei&quot;;&quot;drei&quot;<br />
&quot;vier&quot;;&quot;fuenf&quot;;&quot;sechs&quot;</p>
<p>Das klappt. Nur wenn ein &quot;-Zeichen in meinen Daten vorkommt, dann zerlegt es mir mein CSV. Also habe ich versucht eine Funktion zu schreiben, die meine Daten Escaped.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

static void clearup(char *txt) {
    cout &lt;&lt; &quot;Gegeben: &quot; &lt;&lt; txt &lt;&lt; endl;
    char *back = &quot;&quot;;
    char *ptr;
    ptr = strtok(txt,&quot;\&quot;&quot;);
    while (ptr != NULL) {
        cout &lt;&lt; &quot;Teil: &quot; &lt;&lt; ptr &lt;&lt; &quot; - Platz: &quot; &lt;&lt; strlen(ptr) &lt;&lt; endl;
        strncat(back, ptr, strlen(ptr));
        strncat(back, &quot;\\\&quot;&quot;, 2);
        ptr = strtok(NULL,&quot;\&quot;&quot;);
    }
    txt = back;
}

int main (int argc, char *argv[]) {
    char string[] = &quot;Hier steht was in \&quot;Anfuehrungszeichen\&quot; und ein andere \&quot;Text\&quot; hat das auch.&quot;;
    cout &lt;&lt; &quot;Alter String: &quot; &lt;&lt; string &lt;&lt; endl;
    clearup(string);
    cout &lt;&lt; &quot;Neuer String: &quot; &lt;&lt; string &lt;&lt; endl;
    // Programm Ende
    cout &lt;&lt; &quot;ENDE&quot; &lt;&lt; endl;
    return EXIT_SUCCESS;
}
</code></pre>
<p>Laut sämtlichen Tutorials die ich gefunden habe sollte das ganze gehen. Nur leider bekomme ich immer ein &quot;Segmentation fault&quot; was ja nach Adam Riese (und google) eine Speicherschutzveretzung ist.</p>
<p>Ich bin anscheinend zu doof für, das zu Lösen. Wie kann ich meine Blindheit besiegen?</p>
<p>Danke,<br />
Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/213569/newbee-strncat-und-speicher</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 06:26:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/213569.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 May 2008 11:43:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Newbee - strncat und Speicher on Mon, 19 May 2008 11:43:21 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade eine CSV-Datei zu schreiben folgender Aufbau:<br />
&quot;eins&quot;;&quot;zwei&quot;;&quot;drei&quot;<br />
&quot;vier&quot;;&quot;fuenf&quot;;&quot;sechs&quot;</p>
<p>Das klappt. Nur wenn ein &quot;-Zeichen in meinen Daten vorkommt, dann zerlegt es mir mein CSV. Also habe ich versucht eine Funktion zu schreiben, die meine Daten Escaped.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

static void clearup(char *txt) {
    cout &lt;&lt; &quot;Gegeben: &quot; &lt;&lt; txt &lt;&lt; endl;
    char *back = &quot;&quot;;
    char *ptr;
    ptr = strtok(txt,&quot;\&quot;&quot;);
    while (ptr != NULL) {
        cout &lt;&lt; &quot;Teil: &quot; &lt;&lt; ptr &lt;&lt; &quot; - Platz: &quot; &lt;&lt; strlen(ptr) &lt;&lt; endl;
        strncat(back, ptr, strlen(ptr));
        strncat(back, &quot;\\\&quot;&quot;, 2);
        ptr = strtok(NULL,&quot;\&quot;&quot;);
    }
    txt = back;
}

int main (int argc, char *argv[]) {
    char string[] = &quot;Hier steht was in \&quot;Anfuehrungszeichen\&quot; und ein andere \&quot;Text\&quot; hat das auch.&quot;;
    cout &lt;&lt; &quot;Alter String: &quot; &lt;&lt; string &lt;&lt; endl;
    clearup(string);
    cout &lt;&lt; &quot;Neuer String: &quot; &lt;&lt; string &lt;&lt; endl;
    // Programm Ende
    cout &lt;&lt; &quot;ENDE&quot; &lt;&lt; endl;
    return EXIT_SUCCESS;
}
</code></pre>
<p>Laut sämtlichen Tutorials die ich gefunden habe sollte das ganze gehen. Nur leider bekomme ich immer ein &quot;Segmentation fault&quot; was ja nach Adam Riese (und google) eine Speicherschutzveretzung ist.</p>
<p>Ich bin anscheinend zu doof für, das zu Lösen. Wie kann ich meine Blindheit besiegen?</p>
<p>Danke,<br />
Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1512175</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1512175</guid><dc:creator><![CDATA[stefanjann]]></dc:creator><pubDate>Mon, 19 May 2008 11:43:21 GMT</pubDate></item><item><title><![CDATA[Reply to Newbee - strncat und Speicher on Mon, 19 May 2008 11:48:58 GMT]]></title><description><![CDATA[<p>Was willste nun nehmen?<br />
C<br />
C++<br />
C++/CLI</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1512179</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1512179</guid><dc:creator><![CDATA[witte]]></dc:creator><pubDate>Mon, 19 May 2008 11:48:58 GMT</pubDate></item><item><title><![CDATA[Reply to Newbee - strncat und Speicher on Mon, 19 May 2008 12:05:11 GMT]]></title><description><![CDATA[<p>Eigentlich C++, nur die API von MySQL ist ja C. Ich bekomme sozusagen ursprünglich einen MYSQL_ROW zurück was laut mysql.h ein char** ist. Deswegen wollte ich da über char* machen.</p>
<pre><code class="language-cpp">//..CODE
#include &quot;mysql/mysql.h&quot;
//..CODE
MYSQL_RES *res;
MYSQL_ROW row;
//..CODE
j = 0;
while ((row = mysql_fetch_row(res)) != NULL) {
  j++; // Nummer der Zeile mitschreiben
  cout &lt;&lt; '&quot;' &lt;&lt; j &lt;&lt; '&quot;' &lt;&lt; &quot;;&quot;;
  for (i = 0; i &lt; mysql_num_fields(res); i++) {
    // Hier convertieren, dass &quot;-Zeichen in \&quot;-Zeichen umgewandelt werden.
    cout &lt;&lt; '&quot;' &lt;&lt; row[i] &lt;&lt; '&quot;' &lt;&lt; &quot;;&quot;;
  }
  cout &lt;&lt; endl;
}
//..CODE
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1512196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1512196</guid><dc:creator><![CDATA[stefanjann]]></dc:creator><pubDate>Mon, 19 May 2008 12:05:11 GMT</pubDate></item><item><title><![CDATA[Reply to Newbee - strncat und Speicher on Mon, 19 May 2008 12:05:25 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-18363.html" rel="nofollow">Jochen Kalmbach</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-58.html" rel="nofollow">C++/CLI mit .NET</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1512197</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1512197</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Mon, 19 May 2008 12:05:25 GMT</pubDate></item><item><title><![CDATA[Reply to Newbee - strncat und Speicher on Mon, 19 May 2008 12:06:55 GMT]]></title><description><![CDATA[<p>Sorry für das Posting ins falsche Forum. Hab mich nach dem Login wohl vermausklickt....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1512200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1512200</guid><dc:creator><![CDATA[stefanjann]]></dc:creator><pubDate>Mon, 19 May 2008 12:06:55 GMT</pubDate></item></channel></rss>