<?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[[gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?]]]></title><description><![CDATA[<p>Hallo,</p>
<p>für mein Programm möchte ich eine Fortschrittsanzeige.<br />
Diese sieht erst einmal so aus:</p>
<pre><code class="language-cpp">int fortschritt(long schr, long anz)
{
	if ( schr%anz/25 == 0)

	{
		/* Fortschrittsanzeigen; absolut und prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; schr &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; schr*100/anz &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl;
	}
	return 0;
}
</code></pre>
<p>Nun habe ich festgestellt, dass ab einem bestimmten Wert für <em>schr</em> und <em>anz</em> die Prozentanzeige wieder &quot;zurückspringt&quot;, z.B. von 40 auf 4.</p>
<p>Jetzt bin ich erstmal auf die Lösung umgestiegen, den Datentyp auf double zu ändern, und, damit die Modulo-Operation funktioniert, eine Typumwandlung durchzuführen:</p>
<pre><code class="language-cpp">int fortschritt(double schr, double anz)
{
	if ( long (schr)%long (anz/25) == 0)

	{
		/* Fortschrittsanzeigen; absolutund prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; schr &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; schr*100/anz &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl; // &quot;\r&quot;;
	}
	return 0;
}
</code></pre>
<p>Dann treten leider &quot;krumme&quot; Werte (zB 32000001) für die Fortschrittsanzeige auf, was nicht unbedingt gewünscht ist.</p>
<p>Lange Rede, kurzer Sinn:<br />
Kann ich das irgendwie eleganter lösen?</p>
<p>(Die main() hab ich erstmal weggelassen, wenn sie benötigt wird, poste ich sie noch nach...)</p>
<p>Und bitte seid nachsichtig mit mir, ich hab erst seit 3 Monaten C++-Programmierung an der Schule (bei 2 Wochenstunden Informatik) <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/228314/gelöst-fortschrittsanzeige-läuft-nur-ruckweise-im-linux-terminal-vorher-welcher-datentyp</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 15:45:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/228314.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Nov 2008 17:03:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Mon, 01 Dec 2008 16:53:24 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>für mein Programm möchte ich eine Fortschrittsanzeige.<br />
Diese sieht erst einmal so aus:</p>
<pre><code class="language-cpp">int fortschritt(long schr, long anz)
{
	if ( schr%anz/25 == 0)

	{
		/* Fortschrittsanzeigen; absolut und prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; schr &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; schr*100/anz &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl;
	}
	return 0;
}
</code></pre>
<p>Nun habe ich festgestellt, dass ab einem bestimmten Wert für <em>schr</em> und <em>anz</em> die Prozentanzeige wieder &quot;zurückspringt&quot;, z.B. von 40 auf 4.</p>
<p>Jetzt bin ich erstmal auf die Lösung umgestiegen, den Datentyp auf double zu ändern, und, damit die Modulo-Operation funktioniert, eine Typumwandlung durchzuführen:</p>
<pre><code class="language-cpp">int fortschritt(double schr, double anz)
{
	if ( long (schr)%long (anz/25) == 0)

	{
		/* Fortschrittsanzeigen; absolutund prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; schr &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; schr*100/anz &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl; // &quot;\r&quot;;
	}
	return 0;
}
</code></pre>
<p>Dann treten leider &quot;krumme&quot; Werte (zB 32000001) für die Fortschrittsanzeige auf, was nicht unbedingt gewünscht ist.</p>
<p>Lange Rede, kurzer Sinn:<br />
Kann ich das irgendwie eleganter lösen?</p>
<p>(Die main() hab ich erstmal weggelassen, wenn sie benötigt wird, poste ich sie noch nach...)</p>
<p>Und bitte seid nachsichtig mit mir, ich hab erst seit 3 Monaten C++-Programmierung an der Schule (bei 2 Wochenstunden Informatik) <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/1621271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621271</guid><dc:creator><![CDATA[andy89]]></dc:creator><pubDate>Mon, 01 Dec 2008 16:53:24 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 17:13:44 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int fortschritt_in_prozent(int erledigt, int von)
{
	return (erledigt * 100) / von;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1621278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621278</guid><dc:creator><![CDATA[contramille]]></dc:creator><pubDate>Wed, 26 Nov 2008 17:13:44 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 17:44:55 GMT]]></title><description><![CDATA[<p>Auf die Idee, die Prozentanzeige nochmals auszulagern, bin ich nicht gekommen, danke für den Tipp.<br />
Allerdings wird int als Datentyp nicht reichen...</p>
<p>Aktueller Stand:</p>
<pre><code class="language-cpp">void fortschritt(long schr, long anz)
{
	if ( schr%(anz/25) == 0)

	{
		/* Fortschrittsanzeigen; absolutund prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; schr &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; proz(schr, anz) &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl;
	}
}

double proz(double aktu, double gesa)
{
	return aktu*100/gesa;
}
</code></pre>
<p>Allerdings bleibt das Problem mit zu großen Zahlen, wenn ich jetzt z.B. für schr 4924964562 übergebe, steht da plötzlich</p>
<p>Schritt 85899345 von -2147483648 ( -4 Prozent)</p>
<p>Aber long ist doch der größte Ganzzahltyp.<br />
Natürlich könnte ich jetzt unsigned long nehmen, das würde den Berech verdoppeln. Allerdings geht es da auch irgendwann nicht weiter....</p>
<p>Mit unsigned long sieht es so aus:</p>
<p>? 4924964562 (Eingabe)</p>
<p>Ausgabe:</p>
<p>Schritt 25199890 von 629997266 ( 4 Prozent)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621298</guid><dc:creator><![CDATA[andy89]]></dc:creator><pubDate>Wed, 26 Nov 2008 17:44:55 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 17:55:06 GMT]]></title><description><![CDATA[<p>long ist bei den meisten compilern ein 32bit typ.<br />
64 bit kriegst du mit long long int.<br />
im VS kannst du auch __int64 benutzen.<br />
es empfiehlt sich sowiso eine headerdatei mit typedefs zu erzeugen.<br />
da kann man zur not compilerswitches einbauen und sicher gehen, dass immer die typen benutzt werden, die man auch wollte.<br />
Außerdem erspart es einen die schreibarbeit wie unsigned long long int</p>
<p>hier ein Vorschlag:</p>
<p>MyStdTypes.h</p>
<pre><code class="language-cpp">#ifndef __MyStdTypes_h__
#define __MyStdTypes_h__

typedef   signed char          sint8;
typedef unsigned char          uint8;
typedef   signed short         sint16;
typedef unsigned short         uint16;
typedef   signed int           sint32;
typedef unsigned int           uint32;
typedef   signed long long int sint64;
typedef unsigned long long int uint64;

typedef float  float32;
typedef double float64;

#endif // __MyStdTypes_h__
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1621306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621306</guid><dc:creator><![CDATA[vlad_tepesch]]></dc:creator><pubDate>Wed, 26 Nov 2008 17:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 17:55:30 GMT]]></title><description><![CDATA[<p>vlad_tepesch schrieb:</p>
<blockquote>
<p>hier ein Vorschlag:</p>
</blockquote>
<p>Der schon nur Systemabhängig funktioniert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621307</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Wed, 26 Nov 2008 17:55:30 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 18:11:41 GMT]]></title><description><![CDATA[<p>Mit unsigned long long int scheint das Programm auch langamer zu laufen als nur mit unsigned long int, oder bilde ich mir das nur ein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621316</guid><dc:creator><![CDATA[andy89]]></dc:creator><pubDate>Wed, 26 Nov 2008 18:11:41 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 18:14:38 GMT]]></title><description><![CDATA[<p>andy89 schrieb:</p>
<blockquote>
<p>Mit unsigned long long int scheint das Programm auch langamer zu laufen als nur mit unsigned long int, oder bilde ich mir das nur ein?</p>
</blockquote>
<p>Das kann durchaus sein, abhängig von der OS-Unterstützung und den Prozessor (Registerbreiten...). Wenn mehr Takte für den Datentyp nötig sind, kann das ggf. etwas ausmachen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621317</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Wed, 26 Nov 2008 18:14:38 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 18:15:45 GMT]]></title><description><![CDATA[<p>andy89 schrieb:</p>
<blockquote>
<p>Allerdings geht es da auch irgendwann nicht weiter....</p>
</blockquote>
<p>tja, so ist das halt. es gibt immer eine grenze. mit 32-bit unsigned ints kannst du aber immerhin schon über 40 mio. schritte anzeigen. mit 64-bit dürfte der bereich sicher für die überwiegende mehrheit aller denkbaren anwendungen ausreichen.</p>
<p>andy89 schrieb:</p>
<blockquote>
<p>Mit unsigned long long int scheint das Programm auch langamer zu laufen als nur mit unsigned long int, oder bilde ich mir das nur ein?</p>
</blockquote>
<p>hängt vom system und vom compiler ab. am schnellsten dürfte es mit dem datentyp laufen, der genauso groß ist wie die wortbreite deines computers. vermutlich <code>unsigned int</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621319</guid><dc:creator><![CDATA[contramille]]></dc:creator><pubDate>Wed, 26 Nov 2008 18:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Wed, 26 Nov 2008 18:28:50 GMT]]></title><description><![CDATA[<p>asc schrieb:</p>
<blockquote>
<p>vlad_tepesch schrieb:</p>
<blockquote>
<p>hier ein Vorschlag:</p>
</blockquote>
<p>Der schon nur Systemabhängig funktioniert...</p>
</blockquote>
<p>wie gesagt, an der stelle, kann man compilerweichen einbauen wie:</p>
<pre><code class="language-cpp">#ifndef __MyStdTypes_h__
#define __MyStdTypes_h__

#ifdef _MSC_VER

typedef   signed char          sint8;
typedef unsigned char          uint8;
typedef   signed short         sint16;
typedef unsigned short         uint16;
typedef   signed int           sint32;
typedef unsigned int           uint32;
typedef   signed __int64       sint64;
typedef unsigned __int64       uint64;

typedef float  float32;
typedef double float64;

#elsif _GCC
typedef   signed char          sint8;
typedef unsigned char          uint8;
typedef   signed short         sint16;
typedef unsigned short         uint16;
typedef   signed int           sint32;
typedef unsigned int           uint32;
typedef   signed long long int sint64;
typedef unsigned long long int uint64;
#elsif __xyz
typedef   signed char          sint8;
typedef unsigned char          uint8;
typedef   signed short         sint16;
typedef unsigned short         uint16;
typedef   signed int           sint32;
typedef unsigned int           uint32;

// kann kein int64
//typedef   signed long long int sint64;
//typedef unsigned long long int uint64;

#endif

#endif // __MyStdTypes_h__
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1621336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621336</guid><dc:creator><![CDATA[vlad_tepesch]]></dc:creator><pubDate>Wed, 26 Nov 2008 18:28:50 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Thu, 27 Nov 2008 17:28:21 GMT]]></title><description><![CDATA[<p>Mir ist wieder was neues eingefallen:</p>
<p>Aufruf in der main()</p>
<pre><code class="language-cpp">if (pruef(schritt, anzahl) == 1)
{
	fortschritt(schritt, anzahl);
}
</code></pre>
<p>Und die Funktionen:</p>
<pre><code class="language-cpp">int pruef(ULLONG schr, ULLONG anz)
{
	if ( schr%(anz/25) == 0)
	return 1;
	else
	return 0;
}

void fortschritt(double schr, double anz)
{
	{
		/* Fortschrittsanzeigen; absolutund prozentual */
		cout &lt;&lt;  &quot;Schritt &quot; &lt;&lt; long (schr) &lt;&lt; &quot; von &quot; &lt;&lt; anz;
		cout &lt;&lt;  &quot; ( &quot; &lt;&lt; schr*100/anz &lt;&lt; &quot; Prozent)&quot; &lt;&lt; endl;
	}
}
</code></pre>
<p>Wobei ullong unsigned long long ist.<br />
Ich hab versucht, der pruef-Funktion long-Werte zu übergeben, dann ist da aber wieder dieses Problem mit der Wertüberschreitung...</p>
<p>Ich überlege eigentlich, ob das mit Schritt x von y überhaupt sinnvoll ist.<br />
Ich könnt mir die Fortschrittsanzeige auch so vorstellen:</p>
<p>25% |==============........................|</p>
<p>Das müsste afaik mit Füllzeichen hinzubekommen sein, iwie so:</p>
<pre><code class="language-cpp">cout &lt;&lt; proz &lt;&lt; &quot;% |&quot; &lt;&lt; setw(x) &lt;&lt; setfill ('=') &lt;&lt; &quot;|&quot; &lt;&lt; endl;
</code></pre>
<p>Wobei ich für x eine Schleife bauen würde...</p>
<p>EDIT.</p>
<p>Ausschnitt aus der main:</p>
<pre><code class="language-cpp">y++;
if (y%1000000 == 0)
{
	fortschritt(schritt, anzahl, y);
	// Damit y nicht irgendwann überläuft....
	y = 0;
}
</code></pre>
<p>Und die Funktion:</p>
<pre><code class="language-cpp">void fortschritt(double schr, double anz, long y)
{
	{
		/* Fortschrittsanzeigen; absolutund prozentual */
		cout &lt;&lt; schr*100/anz &lt;&lt; &quot;% |&quot;;
		cout &lt;&lt; setw(y) &lt;&lt; setfill('=') &lt;&lt; &quot;&quot; &lt;&lt; setw(25-y) &lt;&lt; setfill('.') &lt;&lt; &quot;|&quot; &lt;&lt; &quot;\r&quot;;
	}
}
</code></pre>
<p>Naja, das haut nicht ganz hin, wenn ich das ausführe füllen massenweise =s das Terminal....</p>
<p>EDIT2.</p>
<p>Ja, ich habs gemerkt, die Feldbreite wird auf 1 Million gesetzt...</p>
<p>Heut scheint irgendwie nicht mein Tag zu sein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1621985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1621985</guid><dc:creator><![CDATA[andy89]]></dc:creator><pubDate>Thu, 27 Nov 2008 17:28:21 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Fortschrittsanzeige: Läuft Nur ruckweise im Linux-Terminal [vorher: Welcher Datentyp?] on Mon, 01 Dec 2008 16:52:46 GMT]]></title><description><![CDATA[<p>Sorry dass ich kein edit mache...</p>
<p>So, ich bin jetzt auf folgende Lösung gekommen:</p>
<p>innerhalb einer Schleife in der main:</p>
<pre><code class="language-cpp">y++;
	if (y%1000000 == 0)
	{
		fortschritt(schritt, anzahl, y);
		// Damit y nicht irgendwann überläuft....
		y = 0;
	}
</code></pre>
<p>und:</p>
<pre><code class="language-cpp">void fortschritt(double schr, double anz, long y)
{
	{
		int proz;
        /* Fortschrittsanzeigen; absolut und prozentual */
		proz = (schr)*100/anz;
		cout &lt;&lt; proz &lt;&lt; &quot;% |&quot;;
		cout &lt;&lt; setw(proz/4) &lt;&lt; setfill('=') &lt;&lt; &quot;&quot; &lt;&lt; setw(25-(proz/4)) &lt;&lt; setfill('.') &lt;&lt; &quot;|&quot; &lt;&lt; &quot;\r&quot;;
	}
}
</code></pre>
<p>Nun.... unter Windows funktionier die Fortschrittsanzeige richtig schön, bei Eingabe von 1e8 (100*1 Mio) zählt es jedes Prozent durch...</p>
<p>Nur unter Linux (gnome-terminal, xterm) geht es nicht ganz so gut, da dauert es erst einmal eine ganze Weile bis der Statusbalken erscheint, und dann zählt es auch ziemlich ruckartig... (33-66-99)...</p>
<p>Hat jemand eine Ahnung woran das liegen könnte?</p>
<p>EDIT:</p>
<p>Der Code aus der main-Funktion befindet sich übrigens innerhalb einer for-Schleife (sonst würde der Code ja wenig Sinn machen)</p>
<p><strong>Lösung</strong></p>
<p>Ein cout.flush() am Ende der Fortschrittsfunktion</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1622444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1622444</guid><dc:creator><![CDATA[andy89]]></dc:creator><pubDate>Mon, 01 Dec 2008 16:52:46 GMT</pubDate></item></channel></rss>