Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    [c] c'è un modo per impostare il tempo in c? (tipo delay in pascal..)

    mi serviva qualcosa di simile al dalay in pascal per impostare degli intervalli di tempo... c'è un qualche modo?

    grazie.

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,301
    Se non ricordo male, dovrebbe esistere la funzione Sleep() nella libreria Windows.h e prende un intero che indica il tempo in millisecondi.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  3. #3
    in dos.h
    c'e
    sleep(secondi)
    e
    delay(millisecondi)
    pero' non e' standard.

  4. #4
    qualcosa di simile a clrscr, in pascal? (cancellava tutto quello che si era scritto a monitor prima.)

  5. #5
    Utente di HTML.it L'avatar di Kreator
    Registrato dal
    May 2002
    Messaggi
    278
    se sei sulla console puoi anche utilizzare il comando "system" credo ...
    tipo:

    system ("clrscr");

  6. #6
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,301
    Originariamente inviato da Kreator
    se sei sulla console puoi anche utilizzare il comando "system" credo ...
    tipo:

    system ("clrscr");
    La funzione System esegue una chiamata ad un comando della shell, quindi, per cancellare lo schermo, si userà qualcosa del tipo
    codice:
    System("CLS");
    ma anche questa non è standard.

    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  7. #7
    qualcosa che sia compatibile anche con linux?

  8. #8
    per linux ti consiglio di leggere questa pillola
    sui caratteri ANSI
    pillola

  9. #9
    Utente di HTML.it
    Registrato dal
    Dec 2003
    Messaggi
    423
    Per il clrscr() c'è anche conio.h, che non è standard ma ce l'hanno praticamente tutti e si richiama con clrscr() (come Pascal). Invece per l'attesa puoi anche usare la libreria ctime (che è standard) e costruirti una funzione ad hoc tipo questa:

    codice:
    void wait(long int ms)
    {
    	long int end = clock() + ((ms*CLK_TCK)/1000);
    	 
            while (clock() < end);
            
    	return;
    }

  10. #10
    codice:
    From the C FAQ:
    19.37:  How can I implement a delay, or time a user's response, with sub-
            second resolution?
    
    A:      Unfortunately, there is no portable way.  V7 Unix, and derived
            systems, provided a fairly useful ftime() routine with
            resolution up to a millisecond, but it has disappeared from
            System V and POSIX.  Other routines you might look for on your
            system include clock(), delay(), gettimeofday(), msleep(),
            nap(), napms(), nanosleep(), setitimer(), sleep(), times(), and
            usleep().  (A routine called wait(), however, is at least under
            Unix *not* what you want.)  The select() and poll() calls (if
            available) can be pressed into service to implement simple
            delays.  On MS-DOS machines, it is possible to reprogram the
            system timer and timer interrupts.
    
            Of these, only clock() is part of the ANSI Standard.  The
            difference between two calls to clock() gives elapsed execution
            time, and if CLOCKS_PER_SEC is greater than 1, the difference will
            have subsecond resolution.  However, clock() gives elapsed
            processor time used by the current program, which on a
            multitasking system may differ considerably from real time.
    
            If you're trying to implement a delay and all you have available
            is a time-reporting function, you can implement a CPU-intensive
            busy-wait, but this is only an option on a single-user, single-
            tasking machine as it is terribly antisocial to any other
            processes.  Under a multitasking operating system, be sure to
            use a call which puts your process to sleep for the duration,
            such as sleep() or select(), or pause() in conjunction with
            alarm() or setitimer().
    
            For really brief delays, it's tempting to use a do-nothing loop
            like
    
                    long int i;
                    for(i = 0; i < 1000000; i++)
                            ;
    
            but resist this temptation if at all possible!  For one thing,
            your carefully-calculated delay loops will stop working next
            month when a faster processor comes out.  Perhaps worse, a
            clever compiler may notice that the loop does nothing and
            optimize it away completely.
    
            References: H&S Sec. 18.1 pp. 398-9; PCS Sec. 12 pp. 197-8,215-
            6; POSIX Sec. 4.5.2.
    googlando ho trovato questo..
    che conferma quel che dice pprllo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.