<?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[Umwandlung eines C-Strings in seinen Integerwert]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>habe folgene Aufgabenstellung erhalten.Außerdem soll man keine Bibliotheksfunktionen benutzen.</p>
<pre><code>Umwandlung eines C-Strings (ohne Vorzeichen) der eine natürliche Zahl darstellt in
seinen Integerwert. Negative Zahlen werden nicht berücksichtigt. Falls die Zeichenkette
ein Zeichen ungleich den Ziffern 0,1,....,9 enthält, soll eine Fehlermeldung ausgegeben
werden. (Beispiel: Ich tippe 37 auf der Tastatur, d.h. der String s=“37“ wird eingelesen. Mit
dem Ausdruck: i = 10*(’3’-’0’)+’7’-’0’; erhalte ich den Integerwert 37 aus dem String s.
</code></pre>
<p>Leider komme ich nun nicht weiter.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
  char zahl[50];
  cout &lt;&lt; &quot;Eingabe (0-9):&quot;;
  cin &gt;&gt; zahl;

  for(int i = 0; i&lt;=zahl[i]; i++)
  {
      if(zahl[i] &gt;= '0' &amp;&amp; zahl[i] &lt;= '9')
      {

      }
      else
      {
            cout &lt;&lt; &quot;Nur 0-9&quot;;
      }
  }

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/296362/umwandlung-eines-c-strings-in-seinen-integerwert</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 00:12:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/296362.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Dec 2011 11:32:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 11:35:13 GMT]]></title><description><![CDATA[<p>Guten Tag,</p>
<p>habe folgene Aufgabenstellung erhalten.Außerdem soll man keine Bibliotheksfunktionen benutzen.</p>
<pre><code>Umwandlung eines C-Strings (ohne Vorzeichen) der eine natürliche Zahl darstellt in
seinen Integerwert. Negative Zahlen werden nicht berücksichtigt. Falls die Zeichenkette
ein Zeichen ungleich den Ziffern 0,1,....,9 enthält, soll eine Fehlermeldung ausgegeben
werden. (Beispiel: Ich tippe 37 auf der Tastatur, d.h. der String s=“37“ wird eingelesen. Mit
dem Ausdruck: i = 10*(’3’-’0’)+’7’-’0’; erhalte ich den Integerwert 37 aus dem String s.
</code></pre>
<p>Leider komme ich nun nicht weiter.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
  char zahl[50];
  cout &lt;&lt; &quot;Eingabe (0-9):&quot;;
  cin &gt;&gt; zahl;

  for(int i = 0; i&lt;=zahl[i]; i++)
  {
      if(zahl[i] &gt;= '0' &amp;&amp; zahl[i] &lt;= '9')
      {

      }
      else
      {
            cout &lt;&lt; &quot;Nur 0-9&quot;;
      }
  }

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2152240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152240</guid><dc:creator><![CDATA[OPTIMUS]]></dc:creator><pubDate>Sat, 03 Dec 2011 11:35:13 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 11:38:27 GMT]]></title><description><![CDATA[<p>Guck dir mal die <a href="http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange#Zusammensetzung" rel="nofollow">ASCII Tabelle</a> an.</p>
<p>Tipp: Was ist das Ergebnis folgender Rechnung: '4' - '0'?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152244</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 03 Dec 2011 11:38:27 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 11:39:32 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">char zahl[50];
    cout &lt;&lt; &quot;Eingabe (0-9):&quot;;
    cin &gt;&gt; zahl; 
    istringstream iss(zahl); // braucht #include &lt;sstream&gt;
    int i;
    iss &gt;&gt; i;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2152245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152245</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 03 Dec 2011 11:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 11:41:43 GMT]]></title><description><![CDATA[<p>@Gugelmoser<br />
Vorzeichen soll nicht beachtet werden. Sechs, setzen. :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152248</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 03 Dec 2011 11:41:43 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 11:55:13 GMT]]></title><description><![CDATA[<p>Gugelmoser schrieb:</p>
<blockquote>
<pre><code class="language-cpp">char zahl[50];
    cout &lt;&lt; &quot;Eingabe (0-9):&quot;;
    cin &gt;&gt; zahl; 
    istringstream iss(zahl); // braucht #include &lt;sstream&gt;
    int i;
    iss &gt;&gt; i;
</code></pre>
</blockquote>
<p>Wenns wenigstens atoi gewesen wäre ... aber dafür nen fetten Stream konstruieren? Brrr.<br />
Außerdem denke ich er soll es sekbst implementieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152251</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152251</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sat, 03 Dec 2011 11:55:13 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sun, 04 Dec 2011 10:54:31 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Guck dir mal die <a href="http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange#Zusammensetzung" rel="nofollow">ASCII Tabelle</a> an.</p>
<p>Tipp: Was ist das Ergebnis folgender Rechnung: '4' - '0'?</p>
</blockquote>
<p>Das Ergebnis lautet 4.<br />
Leider weiß ich nicht was das bedeutet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152252</guid><dc:creator><![CDATA[OPTIMUS]]></dc:creator><pubDate>Sun, 04 Dec 2011 10:54:31 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 12:03:27 GMT]]></title><description><![CDATA[<p>Der Integerwert von '4' subtrahiert dem Integerwert von '0' ergibt ... 4!<br />
Ergo ist das dein Plan: Du gehst den String von hinten durch, bestimmst den Zahlenwert des chars durch eine Substraktion mit '0', multiplizierst das Ganze mit einer Potenz von 10 und addierst das Ganze.</p>
<p>Zb:</p>
<p>String: &quot;4531&quot;</p>
<p>Integer:<br />
('1' - '0') * 1 +<br />
('3' - '0') * 10 +<br />
('5' - '0') * 100 +<br />
('4' - '0') * 1000</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152255</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sat, 03 Dec 2011 12:03:27 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 12:03:51 GMT]]></title><description><![CDATA[<p>Das Ergebnis lautet: 4. Oh Wunder.</p>
<pre><code class="language-cpp">int i = '0' - '4';
std::cout &lt;&lt; i;
</code></pre>
<p>Wenn jetzt der Groschen nicht fällt..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152256</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 03 Dec 2011 12:03:51 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 12:39:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">unsigned atoi(char const* str)
{
	unsigned result = 0;

	while(*str &amp;&amp; *str &gt;= '0' &amp;&amp; *str &lt;= '9')
		(result *= 10) += *str++ - '0';

	return result;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2152272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152272</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 03 Dec 2011 12:39:51 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 12:39:07 GMT]]></title><description><![CDATA[<p>line ist nicht definiert und der Vergleich mit 0 bzw 9 wird so auch eher nicht sinnvoll sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152278</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sat, 03 Dec 2011 12:39:07 GMT</pubDate></item><item><title><![CDATA[Reply to Umwandlung eines C-Strings in seinen Integerwert on Sat, 03 Dec 2011 12:40:05 GMT]]></title><description><![CDATA[<p>Danke für den Hinweis, ist korrigiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2152281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2152281</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 03 Dec 2011 12:40:05 GMT</pubDate></item></channel></rss>