Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (ANSI-Standard) » Eingabe nach einer Zeit Abbrechen

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 < [ 2 ]
000
17.01.2004, 20:05 Uhr
StBurcher



Hi

Ich möchte eine Eingabe nach einer Zeit abbrechen wenn keine Eingabe erfolgt. Also wenn der User keine Eingabe nach z.B 1 Sekunde macht soll das Programm einfach weiterlaufen.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
17.01.2004, 20:18 Uhr
Pablo
Supertux
(Operator)


Ich glaube, dass man mit nur ANSI nicht machen kann, sicher bin ich aber nicht.

Konsolenprogramm oder Graphische Oberfläche-Programm?
--
A! Elbereth Gilthoniel!
silivren penna míriel
o menel aglar elenath,
Gilthoniel, A! Elbereth!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
17.01.2004, 20:57 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


mit FD_SET's kann man einen timeout einstellen. Einfach mal

man fd_set

da ist sogar als beispiel stdin.
Oder hier unter Windows API ein Thread mit Timeouts.

ob das "rein"-ANSI ist weiß ich aber auch nicht
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
17.01.2004, 20:58 Uhr
Windalf
Der wo fast so viele Posts wie FloSoft...
(Operator)


Solche Dinge macht man meist mit Threads, oft gibts für sowas auch schon fertige funktionen...Ist aber betriebssystemabhängig...
Um dir helfen zu können müssten wir also dein OS wissen und was du genau machen willst...(Damit man nicht mit Kanonen auf Spatzen schiesst)
--
...fleißig wie zwei Weißbrote
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
17.01.2004, 21:27 Uhr
FloSoft
Medialer Over-Flow
(Administrator)



C++:
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int
main(void) {
    fd_set rfds;
    struct timeval tv;
    int retval;

    /* Watch stdin (fd 0) to see when it has input. */
    FD_ZERO(&rfds);
    FD_SET(0, &rfds);
    /* Wait up to five seconds. */
    tv.tv_sec = 5;
    tv.tv_usec = 0;

    retval = select(1, &rfds, NULL, NULL, &tv);
    /* Don't rely on the value of tv now! */

    if (retval == -1)
      perror("select()");
    else if (retval)
      printf("Data is available now.\n");
      /* FD_ISSET(0, &rfds) will be true. */
    else
      printf("No data within five seconds.\n");

    return 0;
}


--
class God : public ChuckNorris { };

Dieser Post wurde am 17.01.2004 um 21:28 Uhr von FloSoft editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
005
18.01.2004, 00:12 Uhr
StBurcher



Hi ,
ich Programmiere in Borland Builder C++ 5. eine C Datei. Kann es aber auch als CPP Datei schreiben. Es währe schön wenn der Befehl OS unabhängig wäre. Aber Primar sollte es Windows sein.
Also wenn eine Scanf oder Cin Anweisung kommt soll er nach 3 Sekunden die Anweisung abbrechen

Dieser Post wurde am 18.01.2004 um 00:13 Uhr von StBurcher editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
006
18.01.2004, 09:01 Uhr
FloSoft
Medialer Over-Flow
(Administrator)



C++:
int main(void)
{
    fd_set rfds;
    struct timeval tv;
    int retval;

    FD_ZERO(&rfds);
    FD_SET(0, &rfds); // 0 für stdin
    tv.tv_sec = 5; // 5 Sekunden warten
    tv.tv_usec = 0;

    retval = select(1, &rfds, NULL, NULL, &tv); // 1 ist ("socket" + 1), unter Windows egal, unter Linux wichtig!

    if (retval == -1)
      perror("select()");
    else if (retval)
    {
      printf("Data is available now.\n");
      /* FD_ISSET(0, &rfds) will be true. */
      //hier sind nun retval-bytes im stdin welche mit cin/fscanf eingelesen werden können
    }  
    else
      printf("No data within five seconds.\n");

    return 0;
}


--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
007
31.01.2004, 19:06 Uhr
StBurcher



Hi danke für die hilfe.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
008
01.02.2004, 16:52 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


Wie ich soeben bemerke: Scheinbar funktioniert diese Methode nicht unter Windows, da gibt select immer -1 zurück. Wie könnte man das "windowsspezifisch" machen?!?
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
009
01.02.2004, 18:38 Uhr
virtual
Sexiest Bit alive
(Operator)


WSA nicht initialisiert, würde ich mal vermuten.
--
Gruß, virtual
Quote of the Month
Ich eß' nur was ein Gesicht hat (Creme 21)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 < [ 2 ]     [ C / C++ (ANSI-Standard) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: