<?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[Tastatureingabe und Auswertung mit Switch - Case]]></title><description><![CDATA[<p>Hallo erstmal an alle <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="🙂"
    /> .</p>
<p>Ich benutze Linux und Eclipse mit CDT Plugin.</p>
<p>Ich befinde mich gerade in der Überarbeitung eines vorhandenen Sourcecodes und wollte eine Tastatureingabe hinzufügen, die mittels einer Switch case Anweisung das eingelesene Zeichen auswertet. Der Code der Methode dazu:</p>
<pre><code>const char* CHAConfiguration::chooseConfigFile(void)
{
	const char *s;

	fprintf(stdout,
			&quot;\nNo config file found. Choose yourself [y]yes or [n]no: &quot;);
	switch (getchar())
	{
	case 'n':
		throw CHAException (__FILE__, __LINE__,
		&quot;Configuration::readIn: Entered config file could not be opened.\n&quot;);
	case 'y':
		fprintf(stdout, &quot;Enter path to a valid configuration file: &quot;);
		scanf(&quot;%as&quot;, &amp;s);
		break;
	}

	return s;
}
</code></pre>
<p>Wenn y gewählt wird, kann man in der nächsten Abfrage den Pfad angeben, bei nein wird eine Exception geschmissen.</p>
<p>Anschließend soll das File geöffnet werden, welches in der Kommandozeile eingetragen wurde.</p>
<pre><code>FILE *confFile;
	if (confFile == NULL)
	{
		do
		{
			confFile = fopen(chooseConfigFile(), &quot;r&quot;);
		}
		while (NULL == confFile);
	}
</code></pre>
<p>Das Problem: Wenn man y wählt und anschließend einen falschen Pfad eingibt, erscheint die Abfrage zwar erneut, aber doppelt.</p>
<p><em>No config file found. Choose yourself [y]yes or [n]no:<br />
No config file found. Choose yourself [y]yes or [n]no:</em></p>
<p>Kann mir jemand sagen, wo der Fehler liegen kann?<br />
Vielen Dank schon mal im Voraus <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="🙂"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/199707/tastatureingabe-und-auswertung-mit-switch-case</link><generator>RSS for Node</generator><lastBuildDate>Sat, 03 Oct 2026 19:18:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/199707.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Dec 2007 10:40:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Tastatureingabe und Auswertung mit Switch - Case on Thu, 06 Dec 2007 10:40:46 GMT]]></title><description><![CDATA[<p>Hallo erstmal an alle <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="🙂"
    /> .</p>
<p>Ich benutze Linux und Eclipse mit CDT Plugin.</p>
<p>Ich befinde mich gerade in der Überarbeitung eines vorhandenen Sourcecodes und wollte eine Tastatureingabe hinzufügen, die mittels einer Switch case Anweisung das eingelesene Zeichen auswertet. Der Code der Methode dazu:</p>
<pre><code>const char* CHAConfiguration::chooseConfigFile(void)
{
	const char *s;

	fprintf(stdout,
			&quot;\nNo config file found. Choose yourself [y]yes or [n]no: &quot;);
	switch (getchar())
	{
	case 'n':
		throw CHAException (__FILE__, __LINE__,
		&quot;Configuration::readIn: Entered config file could not be opened.\n&quot;);
	case 'y':
		fprintf(stdout, &quot;Enter path to a valid configuration file: &quot;);
		scanf(&quot;%as&quot;, &amp;s);
		break;
	}

	return s;
}
</code></pre>
<p>Wenn y gewählt wird, kann man in der nächsten Abfrage den Pfad angeben, bei nein wird eine Exception geschmissen.</p>
<p>Anschließend soll das File geöffnet werden, welches in der Kommandozeile eingetragen wurde.</p>
<pre><code>FILE *confFile;
	if (confFile == NULL)
	{
		do
		{
			confFile = fopen(chooseConfigFile(), &quot;r&quot;);
		}
		while (NULL == confFile);
	}
</code></pre>
<p>Das Problem: Wenn man y wählt und anschließend einen falschen Pfad eingibt, erscheint die Abfrage zwar erneut, aber doppelt.</p>
<p><em>No config file found. Choose yourself [y]yes or [n]no:<br />
No config file found. Choose yourself [y]yes or [n]no:</em></p>
<p>Kann mir jemand sagen, wo der Fehler liegen kann?<br />
Vielen Dank schon mal im Voraus <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="🙂"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1415725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1415725</guid><dc:creator><![CDATA[PiJ]]></dc:creator><pubDate>Thu, 06 Dec 2007 10:40:46 GMT</pubDate></item><item><title><![CDATA[Reply to Tastatureingabe und Auswertung mit Switch - Case on Thu, 06 Dec 2007 10:47:51 GMT]]></title><description><![CDATA[<p>Einer der Klassiker - du beendest deine Eingabe mit einem ENTER - und das bleibt im Tastaturpuffer stehen, nachdem du die vorige Eingabe gelesen (und verarbeitet) hast.</p>
<p>PS: Die Art, wie du scanf() anwendest, sieht nicht ganz sauber aus.</p>
<p>PPS: Ich würde lieber mit C++ Mitteln (IO-Streams und std::string) arbeiten als mit C-Mitteln (FILE*-Funktionen und char-Arrays).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1415729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1415729</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 06 Dec 2007 10:47:51 GMT</pubDate></item><item><title><![CDATA[Reply to Tastatureingabe und Auswertung mit Switch - Case on Thu, 06 Dec 2007 16:02:59 GMT]]></title><description><![CDATA[<p>Hallo CStoll und danke für die Antwort. Hat mir den richtigen Weg gewiesen, hab die switch case Anweisung ersetzt durch eine do while Schleife, mit deren Hilfe ich den Tastaturpuffer leeren konnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1415976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1415976</guid><dc:creator><![CDATA[PiJ]]></dc:creator><pubDate>Thu, 06 Dec 2007 16:02:59 GMT</pubDate></item></channel></rss>