Új hozzászólás Aktív témák

  • emitter

    őstag

    válasz emitter #1323 üzenetére

    najó elég béna voltam, nem godnolkoztam
    szóval müxik, de nem teljesen úgy ahogy én akarom:

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

    int
    input_timeout (int filedes, unsigned int seconds)
    {
    fd_set set;
    struct timeval timeout;

    /* Initialize the file descriptor set. */
    FD_ZERO (&set);
    FD_SET (filedes, &set);

    /* Initialize the timeout data structure. */
    timeout.tv_sec = seconds;
    timeout.tv_usec = 0;

    // select returns 0 if timeout, 1 if input available, -1 if error.
    return select (FD_SETSIZE,
    &set, NULL, NULL,
    &timeout);

    }

    int
    main (void)
    {
    int i=0;
    while(i<10)
    {
    if( input_timeout(STDIN_FILENO, 1) )
    {
    printf(''gomnyomas tortent '');
    printf(''%d\n'',i);
    i++;
    }
    else
    {
    printf(''%d\n'',i);
    i++;
    }
    }
    return 0;
    }


    ugyanis pl. 3 mp-ig várok, ok, számol 3-ig
    aztán nyomok 1 entert, ekkor azt kéne kiírnia, h ''gomnyomas tortent 4''
    majd kéne tovább számolnia, nem?
    ehelyett ezt írja:
    gomnyomas tortent 4
    gomnyomas tortent 5
    gomnyomas tortent 6
    gomnyomas tortent 7
    gomnyomas tortent 8
    gomnyomas tortent 9

    és mindezt 1 pillanat alatt, mintha már nem számolna a timeout :U
    mit rontottam el :F

Új hozzászólás Aktív témák

Hirdetés