<?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[BeispielProgramm-alphapetisches Sortieren-Programmierstil]]></title><description><![CDATA[<p>Ich bin ein C++ - Neuling und habe ein Programm zum alphabetischen Sortieren von Worten geschrieben. Von Programmierstil kann bei diesem Code wohl keine Rede sein <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="🙂"
    /> aber wer Lust hat kann es sich trotzdem mal anschaun und Verbesserungsvorschläge zum Stil, Lesbarkeit usw. bringen.<br />
Einige Fehler sind mir schon so klar.</p>
<ol>
<li>getch() möglichst vermeiden... Habe ich nicht gemacht.</li>
<li>Ich verwende 3 counter mit den nichtssagenden Namen counter, counter2 und counter3.</li>
<li>Ich habe den Code nicht mit Kommentaren versehen.</li>
<li>Die erste while(1)-Schleife ist nicht so geschickt, weil die Variablen bei jedem Programmsurchlauf neu deklariert werden.</li>
</ol>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;

int main()
{
while(1)
{
system(&quot;cls&quot;);
int how_many;
int asc1;
int asc2;
int next=0;
int counter=0,counter2=1,counter3=0;
cout&lt;&lt;&quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;;
cin&gt;&gt;how_many;

string word[how_many];
string word_change;

cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl;

while(counter&lt;how_many)
{
cin&gt;&gt;word[counter];
counter++;
}
counter=0;

while(counter&lt;how_many-1)
{
while(counter+counter2&lt;how_many)
{

while(next==0)
{
asc1=(int) word[counter][counter3];
if(asc1&gt;=97) asc1-=32;
asc2=(int) word[counter+counter2][counter3];
if(asc2&gt;=97) asc2-=32;

if(asc1&gt;asc2)
{
word_change=word[counter+counter2];
word[counter+counter2]=word[counter];
word[counter]=word_change;
next=1;
}
if(asc1==asc2) counter3++;

else next=1;

}
next=0;
counter2++;
counter3=0;
}
counter2=1;
counter++;
}
counter=0;
system(&quot;cls&quot;);

while(counter&lt;how_many)
{
cout&lt;&lt;word[counter]&lt;&lt;endl;
counter++;
}
getch();
}
}
</code></pre>
<p>Danke für jede Antwort</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/155330/beispielprogramm-alphapetisches-sortieren-programmierstil</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 11:13:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/155330.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Aug 2006 20:41:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 20:53:03 GMT]]></title><description><![CDATA[<p>Ich bin ein C++ - Neuling und habe ein Programm zum alphabetischen Sortieren von Worten geschrieben. Von Programmierstil kann bei diesem Code wohl keine Rede sein <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="🙂"
    /> aber wer Lust hat kann es sich trotzdem mal anschaun und Verbesserungsvorschläge zum Stil, Lesbarkeit usw. bringen.<br />
Einige Fehler sind mir schon so klar.</p>
<ol>
<li>getch() möglichst vermeiden... Habe ich nicht gemacht.</li>
<li>Ich verwende 3 counter mit den nichtssagenden Namen counter, counter2 und counter3.</li>
<li>Ich habe den Code nicht mit Kommentaren versehen.</li>
<li>Die erste while(1)-Schleife ist nicht so geschickt, weil die Variablen bei jedem Programmsurchlauf neu deklariert werden.</li>
</ol>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;stdlib.h&gt;
#include &lt;conio.h&gt;
#include &lt;stdio.h&gt;

int main()
{
while(1)
{
system(&quot;cls&quot;);
int how_many;
int asc1;
int asc2;
int next=0;
int counter=0,counter2=1,counter3=0;
cout&lt;&lt;&quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;;
cin&gt;&gt;how_many;

string word[how_many];
string word_change;

cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl;

while(counter&lt;how_many)
{
cin&gt;&gt;word[counter];
counter++;
}
counter=0;

while(counter&lt;how_many-1)
{
while(counter+counter2&lt;how_many)
{

while(next==0)
{
asc1=(int) word[counter][counter3];
if(asc1&gt;=97) asc1-=32;
asc2=(int) word[counter+counter2][counter3];
if(asc2&gt;=97) asc2-=32;

if(asc1&gt;asc2)
{
word_change=word[counter+counter2];
word[counter+counter2]=word[counter];
word[counter]=word_change;
next=1;
}
if(asc1==asc2) counter3++;

else next=1;

}
next=0;
counter2++;
counter3=0;
}
counter2=1;
counter++;
}
counter=0;
system(&quot;cls&quot;);

while(counter&lt;how_many)
{
cout&lt;&lt;word[counter]&lt;&lt;endl;
counter++;
}
getch();
}
}
</code></pre>
<p>Danke für jede Antwort</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110819</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Fri, 04 Aug 2006 20:53:03 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:00:37 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>also das kann man so zusammenfassen</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

void wait ()
{
    std::cin.clear();
    std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
    std::cin.get();
}

int main()
{
	std::cout &lt;&lt; &quot;Enter Words separated by Enter. Enter empty line for exit&quot; &lt;&lt; std::endl;
	std::string line; // aktuelle Eingabe
	std::vector&lt;std::string&gt; lines; // Dynamisches Array für Eingaben

        // Solange Sätze eingeben lassen und speichern bis eine leere Eingabe kommt
	do
	{
      std::getline(std::cin, line);
      lines.push_back(line);
	} while (line.size() &gt; 0);

        // Eingaben sortieren
	std::sort(lines.begin(), lines.end());

        // Sortierte Eingaben der Reihe nach wieder ausgeben
	std::cout &lt;&lt; std::endl &lt;&lt; &quot;sorted lines : &quot; &lt;&lt; std::endl;
	for (std::vector&lt;std::string&gt;::iterator it = lines.begin(); it != lines.end(); ++it)
	  std::cout &lt;&lt; *it &lt;&lt; std::endl;

    wait();
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1110825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110825</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:00:37 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:13:51 GMT]]></title><description><![CDATA[<p>Ertsmal vielen Dank. Mal abgesehen davon, dass ich den Code nicht verstehe sortiert er allerdings Worte mit grossem und kleinem Anfangsbuchstaben falsch.<br />
Trotzdem Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110830</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:13:51 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:18:32 GMT]]></title><description><![CDATA[<p>Hab deinen Code mal formatiert, jetzt kann ich ihn mir besser ansehen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;string&gt; 
#include &lt;stdlib.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;stdio.h&gt; 
using namespace std;
int main() 
{ 
   while(1) 
   { 
      system(&quot;cls&quot;); 
      int how_many; 
      int asc1; 
      int asc2; 
      int next=0; 
      int counter=0,counter2=1,counter3=0; 
      cout&lt;&lt;&quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;; 
      cin&gt;&gt;how_many; 

      string word[how_many]; 
      string word_change; 

      cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl; 

      while(counter&lt;how_many) 
      { 
         cin&gt;&gt;word[counter]; 
         counter++; 
      } 
      counter=0; 

      while(counter&lt;how_many-1) 
      { 
         while(counter+counter2&lt;how_many) 
         { 

            while(next==0) 
            { 
               asc1=(int) word[counter][counter3]; 
               if(asc1&gt;=97) asc1-=32; 
                  asc2=(int) word[counter+counter2][counter3]; 
               if(asc2&gt;=97) asc2-=32; 
                  if(asc1&gt;asc2) 
                  { 
                     word_change=word[counter+counter2]; 
                     word[counter+counter2]=word[counter]; 
                     word[counter]=word_change; 
                     next=1; 
                  } 
               if(asc1==asc2) counter3++; 
               else next=1; 
            } 
            next=0; 
            counter2++; 
            counter3=0; 
         } 
         counter2=1; 
         counter++; 
      } 
      counter=0; 
      system(&quot;cls&quot;); 

      while(counter&lt;how_many) 
      { 
         cout&lt;&lt;word[counter]&lt;&lt;endl; 
         counter++; 
      } 
      getch(); 
   } 
}
</code></pre>
<p><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/1110831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110831</guid><dc:creator><![CDATA[haase2]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:18:32 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:19:17 GMT]]></title><description><![CDATA[<p>Hab deinen Code mal formatiert, jetzt kann ich ihn mir besser ansehen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;string&gt; 
#include &lt;stdlib.h&gt; 
#include &lt;conio.h&gt; 
#include &lt;stdio.h&gt; 
using namespace std;
int main() 
{ 
   while(1) 
   { 
      system(&quot;cls&quot;); 
      int how_many; 
      int asc1; 
      int asc2; 
      int next=0; 
      int counter=0,counter2=1,counter3=0; 
      cout&lt;&lt;&quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;; 
      cin&gt;&gt;how_many; 

      string word[how_many]; 
      string word_change; 

      cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl; 

      while(counter&lt;how_many) 
      { 
         cin&gt;&gt;word[counter]; 
         counter++; 
      } 
      counter=0; 

      while(counter&lt;how_many-1) 
      { 
         while(counter+counter2&lt;how_many) 
         { 

            while(next==0) 
            { 
               asc1=(int) word[counter][counter3]; 
               if(asc1&gt;=97) asc1-=32; 
                  asc2=(int) word[counter+counter2][counter3]; 
               if(asc2&gt;=97) asc2-=32; 
                  if(asc1&gt;asc2) 
                  { 
                     word_change=word[counter+counter2]; 
                     word[counter+counter2]=word[counter]; 
                     word[counter]=word_change; 
                     next=1; 
                  } 
               if(asc1==asc2) counter3++; 
               else next=1; 
            } 
            next=0; 
            counter2++; 
            counter3=0; 
         } 
         counter2=1; 
         counter++; 
      } 
      counter=0; 
      system(&quot;cls&quot;); 

      while(counter&lt;how_many) 
      { 
         cout&lt;&lt;word[counter]&lt;&lt;endl; 
         counter++; 
      } 
      getch(); 
   } 
}
</code></pre>
<p><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/1110832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110832</guid><dc:creator><![CDATA[haase2]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:19:17 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:21:11 GMT]]></title><description><![CDATA[<p>thx <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/1110834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110834</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:21:11 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:23:46 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>std::string wird technisch nach den ASCII-Werten verglichen, und da liegen die großen Buchstaben vor den kleinen.<br />
Wenn dich das stört kannst du für <a href="http://www.cppreference.com/cppalgorithm/sort.html" rel="nofollow">std::sort</a> aber auch eine eigene Vergleichsfunktion definieren, die auf Klein/Großschreibung Rücksicht nimmt.</p>
<p>Wenn das noch zu komplex für dich ist, dann bleib erstmal bei deinem Prinzip, und schau das du folgendes beachtest<br />
- kein system(...) oder getch() verwenden. Alternativen findest du im Konsolen-Subforum<br />
- dann brauchst du auch nicht mehr die alten C-Header<br />
- du kannst anstatt den ASCII-Werten auch direkt die Chars hinschreiben, erhöt Lesbarkeit<br />
- eine systematische Einrückung der Codeblöcke erhöht Lesbarkeit<br />
- ich weiß zwar nicht auf welchem Compiler du das laufen hast, aber bei einem standardkonformen Compiler muß zumindestens nach den Include snoch</p>
<pre><code class="language-cpp">using namespace std;
</code></pre>
<p>hin<br />
- benutzte Funktionen um den Programmablauf übersichtlicher und wiederverwendbarer zu machen</p>
<p>bis bald<br />
akari</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110836</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:23:46 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:30:06 GMT]]></title><description><![CDATA[<p>Mit welchem Compiler hast du übersetzt?</p>
<pre><code class="language-cpp">string word[how_many];
</code></pre>
<p>Gibt bei mir 3 Fehlermeldungen: C2057, C2466 und C2133 (VC 8.0)<br />
Das ist kein C++ ! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110838</guid><dc:creator><![CDATA[haase2]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:30:06 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:31:10 GMT]]></title><description><![CDATA[<p>Mit welchem Compiler hast du übersetzt?</p>
<pre><code class="language-cpp">string word[how_many];
</code></pre>
<p>Gibt bei mir 3 Fehlermeldungen: C2057, C2466 und C2133 (VC 8.0)<br />
Das ist kein C++ ! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110840</guid><dc:creator><![CDATA[haase2]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:31:10 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:33:42 GMT]]></title><description><![CDATA[<p>Dev-C++ 4</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110841</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 21:38:17 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>das liegt einerseits an dem fehlenden namespace (hab ich schon angemerkt), anderseits weil in Standard-C++ auf diese Art keine dynamischen Arrays erstellt werden können, denn dort müssen die Dimensionen immer konstant sein.<br />
Es gibt aber bereits neuere C-Standards, wo sowas möglich ist, und manche Compiler unterstützen soetwas schon.</p>
<p>Aber standardkonform zu C++ wäre ein dynamisches Array mit <em>new</em> zu erstellen oder <em>std::vector</em> zu verwenden.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110845</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Fri, 04 Aug 2006 21:38:17 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Fri, 04 Aug 2006 22:15:45 GMT]]></title><description><![CDATA[<p>akari schrieb:</p>
<blockquote>
<p>Es gibt aber bereits neuere C-Standards[...]</p>
</blockquote>
<p>Aber bislang keine Entsprechung im C++-Standard <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/1110858</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110858</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 04 Aug 2006 22:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 14:00:54 GMT]]></title><description><![CDATA[<p>Squawking schrieb:</p>
<blockquote>
<p>... aber wer Lust hat kann es sich trotzdem mal anschaun und Verbesserungsvorschläge zum Stil, Lesbarkeit usw. bringen.</p>
</blockquote>
<p>Unbedingt den Code formatieren, das Gehirn brauchts! Wenn bei verschachtelten Schleifen alles untereinander steht,<br />
ist das schon fast unlesbar, man kann dann die Kontrollstrukturen nicht mehr auf einen Blick erkennen.<br />
Mit while(1) in der ersten Schleife, haste 'ne Endlosschleife geschrieben. Wie beendet man Dein Programm?<br />
Mit VLA 's programmieren (string word[how_many]) mein VS2005 VC++ 8.0 kann das noch nicht, ganz zu Schweigen vom<br />
C++ Standard der das nicht kennt. Die String-Klasse der STL sollte auch einiges mehr können.<br />
Ich würd's so schreiben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include&lt;locale&gt;
using namespace std;

void sortieren(string* StrPtr, int anzahl){
   bool flag = true;
   while(flag){
      flag = false;
      for (int i = 0; i &lt; anzahl-1; ++i)
         if (StrPtr[i] &gt; StrPtr[i+1]){
            swap(StrPtr[i], StrPtr[i+1]);
            swap(StrPtr[i+anzahl], StrPtr[i+anzahl+1]);
            flag = true;
         }
   }
}
int main() {
   locale loc (&quot;German_Germany&quot;);	
   int anzahl;
   cout &lt;&lt; &quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;; 
   cin &gt;&gt; anzahl;
   if (!anzahl) return 0;
   string* StrPtr = new string [anzahl*2];
   cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl;
   for (int i = 0; i &lt; anzahl; ++i){   
      cin &gt;&gt; StrPtr[i];
      StrPtr[i+anzahl] = StrPtr[i];
      for(size_t x = StrPtr[i].size(); x; --x)
         StrPtr[i][x-1] = tolower(StrPtr[i][x-1], loc);
   }
   sortieren(StrPtr, anzahl);
   for (int i = 0; i &lt; anzahl; i++)
      cout &lt;&lt; endl &lt;&lt; StrPtr[i+anzahl];
   cout &lt;&lt; endl;
   delete[] StrPtr;
   return 0;
}
</code></pre>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110890</guid><dc:creator><![CDATA[Helmut S.]]></dc:creator><pubDate>Sat, 05 Aug 2006 14:00:54 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 11:06:48 GMT]]></title><description><![CDATA[<p>Danke an Helmut S.<br />
Mit etwas Arbeit kann ich diesen code denke ich sehr gut verstehen und viel lernen.<br />
Vorerst werde ich mir aber erstmal einen ordentlichen Compiler besorgen. Meiner ist wohl etwas veraltet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110985</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 11:06:48 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 11:23:26 GMT]]></title><description><![CDATA[<p>Habe mir nun eine neuere Version besorgt und bekomme darauf den code von Helmut auch zum laufen. Nur gibt es da noch ein Problem: Manche Worte werden nicht richtig geordnet. Ich habe es mit meinem Programm verglichen, dort funktioniert es. Hat wieder was mit der Gross-und Klein-Schreibung zu tun. kommt vor, wenn mehrere Buchstaben im Wort gross geschrieben sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1110993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1110993</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 11:23:26 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 14:09:04 GMT]]></title><description><![CDATA[<p>Squawking schrieb:</p>
<blockquote>
<p>... kommt vor, wenn mehrere Buchstaben im Wort gross geschrieben sind.</p>
</blockquote>
<p>Hab diesen Fehler behoben, siehe Programm. Wie gesagt, die String-Klasse der STL sollte mehr leisten, würde den Programmierern Arbeit sparen.<br />
mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111098</guid><dc:creator><![CDATA[Helmut S.]]></dc:creator><pubDate>Sat, 05 Aug 2006 14:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 15:44:43 GMT]]></title><description><![CDATA[<p>Alles klar. Danke.Das Programm stürzt bei mir aber sofort nach Aufruf ab. Den Code werde ich mir trotzdem mal anschauen. Noch eine Frage:<br />
Dein Code ist im Vergleich zu meinem relativ kurz.<br />
Nun zu meiner Frage: Liegt das hauptsächlich daran, dass du die vorgefertigten Funktionen aus der STL benutzt?<br />
Ich habe ja die ganzen Sortier-Schleifen selber geschrieben und wüsste nicht, wie das kürzer gehen soll, wenn man alles selber schreibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111143</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 15:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 16:32:29 GMT]]></title><description><![CDATA[<p>Bei mir läufts. Ist vor allem die STL-Funktion swap(,) die meinen Code kürzer gemacht hat.<br />
mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111174</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111174</guid><dc:creator><![CDATA[Helmut S.]]></dc:creator><pubDate>Sat, 05 Aug 2006 16:32:29 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 17:50:09 GMT]]></title><description><![CDATA[<p>Also wenn ich versuche, dass kompilierte Programm aus der Eingabeaufforderung zu starten bekomme ich folgenden Fehler:</p>
<p>This application has requested the Runtime to terminate it in an unusual way.<br />
Please contact the application`s support team for more information.</p>
<p>KA</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111213</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 17:50:09 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 19:17:45 GMT]]></title><description><![CDATA[<p>Squawking schrieb:</p>
<blockquote>
<p>Also wenn ich versuche, dass kompilierte Programm aus der Eingabeaufforderung zu starten bekomme ich folgenden Fehler:</p>
<p>This application has requested the Runtime to terminate it in an unusual way.<br />
Please contact the application`s support team for more information.</p>
<p>KA</p>
</blockquote>
<p>Mit VS2005 VC++ 8.0 erstellt, funktioniert das Programm.<br />
Mit GNU GCC Compiler 3.4.6 (CodeBlocks 1.0) unter WindowsXP ersellt, kommt es auch bei mir zu der obigen Fehlermeldung.<br />
Hat jemand eine Erklärung dafür?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111261</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111261</guid><dc:creator><![CDATA[Helmut S.]]></dc:creator><pubDate>Sat, 05 Aug 2006 19:17:45 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 19:22:30 GMT]]></title><description><![CDATA[<p>Nun ja. Ich vermende winXP und have es mit Dev C++ 5 kompiliert. Würde auch gerne wissen, wo da das Problem steckt. Wer helfen kann....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111264</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 19:22:30 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 19:58:23 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
//#include&lt;locale&gt;
using namespace std;

void sortieren(string* StrPtr, int anzahl){
   bool flag = true;
   while(flag){
      flag = false;
      for (int i = 0; i &lt; anzahl-1; ++i)
         if (StrPtr[i] &gt; StrPtr[i+1]){
            swap(StrPtr[i], StrPtr[i+1]);
            swap(StrPtr[i+anzahl], StrPtr[i+anzahl+1]);
            flag = true;
         }
   }
}
int main() {
//   locale loc (&quot;German_Germany&quot;);
   int anzahl;
   cout &lt;&lt; &quot;Wie viele Worte wollen Sie alphabetisch sortieren? &quot;;
   cin &gt;&gt; anzahl;
   if (!anzahl) return 0;
   string* StrPtr = new string [anzahl*2];
   cout&lt;&lt;&quot;Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: &quot;&lt;&lt;endl;
   for (int i = 0; i &lt; anzahl; ++i){
      cin &gt;&gt; StrPtr[i];
      StrPtr[i+anzahl] = StrPtr[i];
      for(size_t x = StrPtr[i].size(); x; --x)
         StrPtr[i][x-1] = tolower((int)StrPtr[i][x-1]);//&lt;----------
   }
   sortieren(StrPtr, anzahl);
   for (int i = 0; i &lt; anzahl; i++)
      cout &lt;&lt; endl &lt;&lt; StrPtr[i+anzahl];
   cout &lt;&lt; endl;
   delete[] StrPtr;
   return 0;
}
</code></pre>
<p>So läufts jetzt auch mit GCC-Compiler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111283</guid><dc:creator><![CDATA[Helmut S.]]></dc:creator><pubDate>Sat, 05 Aug 2006 19:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to BeispielProgramm-alphapetisches Sortieren-Programmierstil on Sat, 05 Aug 2006 20:09:41 GMT]]></title><description><![CDATA[<p>Vom feinsten. Nun funktioniert es bei mir auch. Soweit ist denke ich auch alles richtig. Jetzt kann ich mich ranmachen und mir die ganzen templates und so angucken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111291</guid><dc:creator><![CDATA[Squawking]]></dc:creator><pubDate>Sat, 05 Aug 2006 20:09:41 GMT</pubDate></item></channel></rss>