<?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[Buchstaben bei einem char* anhängen]]></title><description><![CDATA[<p>Wie hänge ich ohne die Standartfunktionen wie sprintf einen Buchstaben an ein char* an?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/159058/buchstaben-bei-einem-char-anhängen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 07:31:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/159058.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Sep 2006 15:39:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 15:39:03 GMT]]></title><description><![CDATA[<p>Wie hänge ich ohne die Standartfunktionen wie sprintf einen Buchstaben an ein char* an?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135309</guid><dc:creator><![CDATA[RobthaR]]></dc:creator><pubDate>Mon, 11 Sep 2006 15:39:03 GMT</pubDate></item><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 15:43:23 GMT]]></title><description><![CDATA[<p>Gar nicht. char*-Strings haben eine feste Größe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135314</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Mon, 11 Sep 2006 15:43:23 GMT</pubDate></item><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 15:43:32 GMT]]></title><description><![CDATA[<p>Mit <a href="http://www.cppreference.com/stdstring/strcat.html" rel="nofollow">strcat</a> bzw. der sichereren Variante <a href="http://www.cppreference.com/stdstring/strncat.html" rel="nofollow">strncat</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135315</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Mon, 11 Sep 2006 15:43:32 GMT</pubDate></item><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 15:50:24 GMT]]></title><description><![CDATA[<p>RobthaR schrieb:</p>
<blockquote>
<p>Wie hänge ich ohne die Standartfunktionen wie sprintf einen Buchstaben an ein char* an?</p>
</blockquote>
<p>Da dies hier ein C++-Forum ist: benutz die Klasse std::string und die Standardfunktionen.</p>
<p>Ansonsten wird es aufwendig:</p>
<pre><code class="language-cpp">size_t string_length(char const* str)
{
    size_t len = 0;
    for (; *str != '\0'; ++str, ++len);
    return len;
}

char* append(char const* str, char ch)
{
    size_t len = string_length(str);
    char* new_str = new char[len + 2];
    for (char* i = new_str; *str != '\0'; ++i, ++str)
        *i = *str;
    new_str[len] = ch;
    new_str[len + 1] = 0;
    return new_str;
}

int main()
{
    using namespace std;

    char text[] = &quot;Hallo&quot;;
    cout &lt;&lt; string_length(text) &lt;&lt; endl;

    char* new_text = append(text, 's');
    cout &lt;&lt; new_text &lt;&lt; endl;
    cout &lt;&lt; string_length(new_text) &lt;&lt; endl;
    delete [] new_text;
}
</code></pre>
<p>(Ungetestet!)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135320</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Mon, 11 Sep 2006 15:50:24 GMT</pubDate></item><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 16:00:03 GMT]]></title><description><![CDATA[<p>Konrad Rudolph schrieb:</p>
<blockquote>
<p>Ansonsten wird es aufwendig:</p>
</blockquote>
<p>gar nicht. geht auch einfach:</p>
<pre><code>void append (char *str, char c)
{
  while (*str)
    str++;
  *str++ = c;
  *str = 0;     
}
</code></pre>
<p>musste nur sicherstellen dass noch platz für das zeichen da ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135326</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135326</guid><dc:creator><![CDATA[net 0]]></dc:creator><pubDate>Mon, 11 Sep 2006 16:00:03 GMT</pubDate></item><item><title><![CDATA[Reply to Buchstaben bei einem char* anhängen on Mon, 11 Sep 2006 16:13:10 GMT]]></title><description><![CDATA[<p>net schrieb:</p>
<blockquote>
<p>Konrad Rudolph schrieb:</p>
<blockquote>
<p>Ansonsten wird es aufwendig:</p>
</blockquote>
<p>gar nicht. geht auch einfach:<br />
[...]<br />
musste nur sicherstellen dass noch platz für das zeichen da ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Eben. Das ist ja das aufwendige daran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1135338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1135338</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Mon, 11 Sep 2006 16:13:10 GMT</pubDate></item></channel></rss>