<?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[Zeitfunktion]]></title><description><![CDATA[<p>Wie würdet ihr folgende Funktion schreiben. Sie sollte ungefähr so aussehen:</p>
<pre><code class="language-cpp">void timer(short &amp;var, short millisecs);
</code></pre>
<p>Und jetzt soll alle &quot;millisecs&quot; Millisekunden zu &quot;&amp;var&quot; eine &quot;1&quot; addiert werden?<br />
Wie würdet ihr das lösen? Ich hab eigentlich nich so n Plan von &lt;ctime&gt; und Zeit allgemein. Mit einer static Vriable vll.? Und &quot;time(0)&quot;?<br />
Würde mich über eure Vorschläge freuen.</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/215501/zeitfunktion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 06:09:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/215501.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Jun 2008 20:06:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 20:06:14 GMT]]></title><description><![CDATA[<p>Wie würdet ihr folgende Funktion schreiben. Sie sollte ungefähr so aussehen:</p>
<pre><code class="language-cpp">void timer(short &amp;var, short millisecs);
</code></pre>
<p>Und jetzt soll alle &quot;millisecs&quot; Millisekunden zu &quot;&amp;var&quot; eine &quot;1&quot; addiert werden?<br />
Wie würdet ihr das lösen? Ich hab eigentlich nich so n Plan von &lt;ctime&gt; und Zeit allgemein. Mit einer static Vriable vll.? Und &quot;time(0)&quot;?<br />
Würde mich über eure Vorschläge freuen.</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527284</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Wed, 11 Jun 2008 20:06:14 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 20:23:41 GMT]]></title><description><![CDATA[<p>Darfst du Betriebssystemfunktionen verwenden? Wenn ja, dann initalisiere dir doch einen Timer mit der entsprechenden API. (In Windows könntest du den Multimedia Timer verwenden. <a href="http://www.codeworx.org/cpp_tuts_1_3.php" rel="nofollow">Link zu einem Beispiel</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527291</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527291</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Wed, 11 Jun 2008 20:23:41 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 20:21:03 GMT]]></title><description><![CDATA[<p>Nein, es sollte alles über Standard C++ laufen.</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527292</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Wed, 11 Jun 2008 20:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 20:37:26 GMT]]></title><description><![CDATA[<p>Da bin ich leider auch nicht so firm drin, aber vielleicht hilft dir dieser <a href="http://www.willemer.de/informatik/cpp/timelib.htm" rel="nofollow">Link</a> mit der Funktion gettimeofday() weiter... da time() soweit ich weiß nur sekunden genau läuft.</p>
<p>Gruß<br />
Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527301</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Wed, 11 Jun 2008 20:37:26 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 21:27:41 GMT]]></title><description><![CDATA[<p>Das hier wäre schon mal ein anfang:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;ctime&gt;
using namespace std;

void timer(short &amp;var, short secs);

int main()
{
    short a=0;
    while(1)
    {
        timer(a,2);
        if(a==2) cout &lt;&lt; &quot;2 Sec. \n&quot;;
    }

    return 0;
}

void timer(short &amp;var, short secs)
{
    static long save_time  = 0;
    static short save_secs = 0;

    //Sekunden speichern, sodass nicht bei jedem Funktionsaufruf neuer Wert entsteht.
    if(save_secs == 0)
    {
        save_secs = secs;
    }

    //Zeit Startpunkt setzen
    if(save_time == 0)
    {
        save_time = time(0);
    }
    else
    {
        if(time(0) &gt; (save_time + save_secs))
        {
            ++var;
            save_time = 0;
            save_secs = 0;
        }
    }
}
</code></pre>
<p>Aber das geht halt jetzt leider nur mit ganzen Sekunden? Kann mir vll. jemand sagen wie ich dass nun mit Millisekunden machen soll?<br />
Soll ichs umschreiben, ganz neu schreiben....? Wer hat Ideen?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527327</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Wed, 11 Jun 2008 21:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Thu, 12 Jun 2008 06:52:38 GMT]]></title><description><![CDATA[<p>war nachtunsinn..</p>
<p>noch ein link zu einer damaligen idee von volkard<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-126011-and-highlight-is-millisekunden.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-126011-and-highlight-is-millisekunden.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527334</guid><dc:creator><![CDATA[elise]]></dc:creator><pubDate>Thu, 12 Jun 2008 06:52:38 GMT</pubDate></item><item><title><![CDATA[Reply to Zeitfunktion on Wed, 11 Jun 2008 23:37:13 GMT]]></title><description><![CDATA[<blockquote>
<p>Kann mir vll. jemand sagen wie ich dass nun mit Millisekunden machen soll</p>
</blockquote>
<p>Mit ISO C++: garnicht.<br />
Könntest du vielleicht die Forderung &quot;es sollte alles über Standard C++ laufen&quot; etwas aufweichen und in ein (viel realistischeres) &quot;es sollte halbwegs portierbar sein&quot; umwandeln?<br />
Dann könntest du nämlich z.B. die Boost verwenden: <a href="http://www.boost.org/doc/libs/1_35_0/doc/html/date_time/posix_time.html#ptime_from_clock" rel="nofollow">http://www.boost.org/doc/libs/1_35_0/doc/html/date_time/posix_time.html#ptime_from_clock</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1527359</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1527359</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 11 Jun 2008 23:37:13 GMT</pubDate></item></channel></rss>