|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
[C] Pausa - system("PAUSE")
Salve a tutti, volevo chiedervi un modo semplice per far fermare il programma e leggere a schermo i risultati. Sotto windows utilizzo system("PAUSE") ma non è standard e sotto Linux non va. A questo punto mi ero creato la funzione pausa:
Codice:
void pausa(void) { printf("\nPAUSE\nPremere INVIO...."); getchar(); } ![]() Grazie a tutti.
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Forse il buffer di input non è vuoto, quindi getchar prende il suo char e l'esecuzione va avanti
|
![]() |
![]() |
![]() |
#3 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Quote:
grazie
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
|
![]() |
![]() |
![]() |
#4 |
Member
Iscritto dal: Jul 2008
Città: Nel mio studio
Messaggi: 168
|
Codice:
while(1) getchar();
__________________
Since Rocco Siffredi, the saying "pain in the ass" got a total new meaning |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
due getchar are the way
![]() |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Sep 2005
Città: Opinions are like assholes: anybody has one...
Messaggi: 34290
|
oppure molto + semplicemente
system("read"); ![]()
__________________
Ну давай !! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cina, bugiardo - stolen conto: non paghi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NON CERCO PIU' UN ALIMENTATORE DECENTE ----------------> LINK |
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
|
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: Sep 2005
Città: Opinions are like assholes: anybody has one...
Messaggi: 34290
|
ho appena provato per sicurezza su ubuntu e funziona
scrivi read da shell e il controllo attenderà che premi un tasto come normale che sia analogamente se vuoi fare una lettura ritardata c'e' sempre system("sleep x"); con x= secondi di delay potresti mettere system("sleep 5"); per sospendere l'esecuzione per 5 sec e avere il tempo di leggere cmq la read per unix è l'alternativa a pause di dos
__________________
Ну давай !! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cina, bugiardo - stolen conto: non paghi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NON CERCO PIU' UN ALIMENTATORE DECENTE ----------------> LINK |
![]() |
![]() |
![]() |
#9 |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Pensavo che la cosa fosse piu semplice ed invece no.
1) Il ciclo while non mi convince l'uscita con ctrl+c. 2) Il doppio getchar va bene la prima volta ma se il buffer è vuoto la seconda volta devo dare due enter. 3) system("read") mi costringe ad usare system("PAUSE") per rendere il programma identico anche sotto Windows. Se svuotassi il buffer prima di dare getchar? Non so come si fa. Cmq ho provato gets e funziona ma quando compilo mi da il seguente warning: Codice:
In function `pausa': main.c:(.text+0x2a): warning: the `gets' function is dangerous and should not be used. ![]()
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
![]() |
![]() |
![]() |
#10 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 1059
|
Codice:
void pausa(void) { printf("\nPAUSE\nPremere INVIO...."); fflush(stdin); getchar(); } ![]() |
![]() |
![]() |
![]() |
#11 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Quote:
![]() Cito: "il comportamento di fflush sugli stream di input non è definito. fflush è fatta per operare sugli stream di output." Almeno non sono il solo ![]()
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
|
![]() |
![]() |
![]() |
#12 | |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 1059
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#13 |
Senior Member
Iscritto dal: Sep 2005
Città: Opinions are like assholes: anybody has one...
Messaggi: 34290
|
ma tu vuoi creare un prg sia per linux che per win retrocompatibile ?
__________________
Ну давай !! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cina, bugiardo - stolen conto: non paghi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NON CERCO PIU' UN ALIMENTATORE DECENTE ----------------> LINK |
![]() |
![]() |
![]() |
#14 | |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Quote:
Per adesso mi sa che l'unica soluzione è l'utilizzo di direttive. Ho trovato questa soluzione ma per adesso l'ho provata una mezza volta e mi ha dato un po di problemi. Dove la devo mettere? Codice:
#ifdef _WIN const char* pulisci = "cls"; #elseif #ifdef LINUX const char* pulisci = "clear"; #else #error "OS NOT SUPPORTED" #endif ... system(pulisci); ![]() ![]()
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
|
![]() |
![]() |
![]() |
#15 |
Senior Member
Iscritto dal: Nov 2005
Messaggi: 2774
|
Ecco la mia soluzione, fammi sapere se funziona anche su linux:
Codice:
#include <stdio.h> int main(int argc,char*argv[]){ getchar(); fseek(stdin,0,SEEK_END); getchar(); return 0; } |
![]() |
![]() |
![]() |
#16 | |
Senior Member
Iscritto dal: Sep 2005
Città: Opinions are like assholes: anybody has one...
Messaggi: 34290
|
Quote:
cmq stamattina funzionava se vuoi disimpegnarti dal sistema operativo allora ci vuole un getche(); occhio alle librerie ![]() pero' ho paura che vada solo su dos....
__________________
Ну давай !! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cina, bugiardo - stolen conto: non paghi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NON CERCO PIU' UN ALIMENTATORE DECENTE ----------------> LINK |
|
![]() |
![]() |
![]() |
#17 |
Senior Member
Iscritto dal: May 2004
Città: Londra (Torino)
Messaggi: 3692
|
e la (giustamente) bistrattata scanf?
PS: Non tocco C puro dal 1993, e scanf forse l'ho usato una volta sola...
__________________
Se pensi che il tuo codice sia troppo complesso da capire senza commenti, e' segno che molto probabilmente il tuo codice e' semplicemente mal scritto. E se pensi di avere bisogno di un nuovo commento, significa che ti manca almeno un test. |
![]() |
![]() |
![]() |
#18 |
Senior Member
Iscritto dal: May 2004
Città: Napoli
Messaggi: 773
|
Ma un ide furbetto che ti tiene la finestra aperta?
![]()
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. --Gerald Weinberg |
![]() |
![]() |
![]() |
#19 |
Member
Iscritto dal: Jul 2008
Città: Nel mio studio
Messaggi: 168
|
ma lanciare il programma da terminale?
![]()
__________________
Since Rocco Siffredi, the saying "pain in the ass" got a total new meaning |
![]() |
![]() |
![]() |
#20 |
Senior Member
Iscritto dal: May 2004
Città: Napoli
Messaggi: 773
|
Vabè, può essere noioso, soprattutto se si fanno piccoli programmini di prova e si modificano più e più volte per testare il comportamento
![]()
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization. --Gerald Weinberg |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:31.