<?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[Problem mit Code]]></title><description><![CDATA[<p>Guten Tag ich habe ein Problem mit diesem Codeschnipsel:</p>
<pre><code>string PasswortInput()
{
    char CurrentKey[1];
    char Word[100];
    int a = 0;
    bool Ende = false;

    while(!Ende)
    {
        if(kbhit())
        {
            CurrentKey[0] = getch();
            switch (CurrentKey[0])
            {
                case 0x0D:
                    Ende = true;
                    break;
                case 0x08:
                    cout &lt;&lt;  &quot;\b \b&quot;;
                    Word[a--] = 0; // Wie kann ich hier das Zeichen &quot;löschen&quot;?
                    break;
                default:
                    cout &lt;&lt; &quot;*&quot;;
                    Word[a] = CurrentKey[0];
                    a++;
                    break;
            }
        }
    }
    string endInput(Word);

    return(endInput);
}
</code></pre>
<p>Und zwar bekomm ich manchmal als Rückgabewert das korrekte Wort und manchmal das Wort mit Sonderzeichen am Schluss. Zum Test hab ich &quot;asd&quot; eingegeben und das kam auch so zurück. Dann hab ich das Programm nochmal neu gestartet und wieder &quot;asd&quot; eingegeben und bekam dann &quot;asd&quot; mit Sonderzeichen zurück. Weiß einer wieso? Und wie kann ich, wenn Backspace gedrückt wurde, das letzte Zeichen löschen? (Stelle ist im Code markiert)</p>
<p>Danke Schonmal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/237836/problem-mit-code</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 05:28:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237836.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Apr 2009 14:58:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Code on Thu, 02 Apr 2009 14:58:54 GMT]]></title><description><![CDATA[<p>Guten Tag ich habe ein Problem mit diesem Codeschnipsel:</p>
<pre><code>string PasswortInput()
{
    char CurrentKey[1];
    char Word[100];
    int a = 0;
    bool Ende = false;

    while(!Ende)
    {
        if(kbhit())
        {
            CurrentKey[0] = getch();
            switch (CurrentKey[0])
            {
                case 0x0D:
                    Ende = true;
                    break;
                case 0x08:
                    cout &lt;&lt;  &quot;\b \b&quot;;
                    Word[a--] = 0; // Wie kann ich hier das Zeichen &quot;löschen&quot;?
                    break;
                default:
                    cout &lt;&lt; &quot;*&quot;;
                    Word[a] = CurrentKey[0];
                    a++;
                    break;
            }
        }
    }
    string endInput(Word);

    return(endInput);
}
</code></pre>
<p>Und zwar bekomm ich manchmal als Rückgabewert das korrekte Wort und manchmal das Wort mit Sonderzeichen am Schluss. Zum Test hab ich &quot;asd&quot; eingegeben und das kam auch so zurück. Dann hab ich das Programm nochmal neu gestartet und wieder &quot;asd&quot; eingegeben und bekam dann &quot;asd&quot; mit Sonderzeichen zurück. Weiß einer wieso? Und wie kann ich, wenn Backspace gedrückt wurde, das letzte Zeichen löschen? (Stelle ist im Code markiert)</p>
<p>Danke Schonmal im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689947</guid><dc:creator><![CDATA[Nepp]]></dc:creator><pubDate>Thu, 02 Apr 2009 14:58:54 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Code on Thu, 02 Apr 2009 15:31:52 GMT]]></title><description><![CDATA[<p>Nepp schrieb:</p>
<blockquote>
<p>[code]<br />
...<br />
case 0x0D:<br />
Ende = true;<br />
break;<br />
case 0x08:<br />
...</p>
</blockquote>
<p>Du musst das char array noch terminieren</p>
<pre><code class="language-cpp">// machen alle 3 das selbe
Word[a] = '\0';
Word[a] = 0x00;
Word[a] = 0;
</code></pre>
<p>oder du füllst das array gleich mit 0.</p>
<pre><code class="language-cpp">char Word[100];
memset (Word, 0x00, sizeof (Word));
</code></pre>
<p>Nepp schrieb:</p>
<blockquote>
<p>[code]<br />
case 0x08:<br />
cout &lt;&lt; &quot;\b \b&quot;;<br />
Word[a--] = 0; // Wie kann ich hier das Zeichen &quot;löschen&quot;?<br />
break;</p>
</blockquote>
<p>Könntest z.B.:</p>
<pre><code class="language-cpp">case 0x08:
  cout &lt;&lt;  &quot;\b \b&quot;;
  a--;
  Word[a] = 0;
  // Word[--a] = 0; wenn ich nicht falsch liege sollte das auch gehen (aber ned mein stil ;) )
  break;
</code></pre>
<p>Aber dazu sollte man noch sagen, wenn du schon C++ progst nimm std::string</p>
<p>Keros</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689960</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689960</guid><dc:creator><![CDATA[Keros]]></dc:creator><pubDate>Thu, 02 Apr 2009 15:31:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Code on Thu, 02 Apr 2009 17:18:47 GMT]]></title><description><![CDATA[<p>Also danke, jetzt funktioniert es und auch das mit dem Löschen geht. Ja ich versuch schon immer std::string zu verwenden, aber wie wäre das im obigen Code möglich? Das hat er nämlich nicht geschluckt:</p>
<pre><code class="language-cpp">string str;
str.c_str() = getch();
</code></pre>
<p>Ich bin leider noch Anfänger, also erbitte ich um Nachsicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1690012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1690012</guid><dc:creator><![CDATA[Nepp]]></dc:creator><pubDate>Thu, 02 Apr 2009 17:18:47 GMT</pubDate></item></channel></rss>