Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi!

Ich brauche eine Schleife in C oder C++, die eine vorgegebene Zeit (30 sec.) auf eine Benutzereingabe wartet (beliebige Taste).

Ausgehend davon ob der Benutzer in diesen 30 sec. eine Taste drückt oder die Zeit verstreichen lässt werden unterschiedliche Funktionen aufgerufen.

Hat jemand eine Idee???

Schönen Gruß und Danke!

Try this:

#include <conio.h>
#include <stdio.h>
#include <time.h>

void main() {
long Ticks = clock();
int Key = 0;

while (clock() < (Ticks + 30000)) {
if (kbhit()) {
Key = getch();
break;
}
}

if (Key)
printf("Key %d pressed\n", Key);
}[/php]

Original geschrieben von Stevie


while (clock() < (Ticks + 30000)) {
[/php]

clock_t clock(void);

This function returns the number of clock ticks since an arbitrary time, actually, since the first call to clock, which itself returns zero. The number of tics per second is CLOCKS_PER_SEC.

Hallo,

in Standard-C funktioniert das nicht, da Benutzereingaben blockieren. Für welches Betriebssystem entwickelst Du denn? Unter Unix liesse sich das beispielsweise über einen Signal-Handler realisieren, der über ein Sigalarm aufgerufen wird.

Nic

Hi!

Ich habe Windows NT oder XP mit dem Visual Studio zur Verfügung.

Leider keine Chance das unter Unix zu machen ;-)

Gruß,

fg

Ich hab's mit MSVS 6 auf WinNT ausprobiert und es klappt. Ich versteh nicht, was ihr für ein Problem habt!?

Hallo,

Original geschrieben von Stevie

Ich hab's mit MSVS 6 auf WinNT ausprobiert und es klappt. Ich versteh nicht, was ihr für ein Problem habt!?

Das Problem ist, dass die Fragestellung nur plattformabhängig gelöst werden kann, Der gepostete läuft damit nicht unter Linux/Unix usw. Ohne Angabe der Zielplattform (fehlt im ersten Artikel), läßt sich also keine brauchbare Lösung formulieren.

Nic

Hi!

OK,Plattform hatte ich im ersten Beitrag versgessen :eek:

Sollte es jetzt endgültig unter NT/VS implementieren und damit hat die Lösung von Stevie geklappt.

Danke und schönen Gruß :)

fg

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.