View Full Version : [ C ] IF (Tastopremuto == "Invio")
duobutch
23-12-2005, 12:54
Piccolo quesito :doh: :
IF (Tastopremuto == "Invio")
Come si può "tradurre" questa espressione in c++?
frizzo28
23-12-2005, 13:07
Ecco il codice per turbo c++ 3.0 non so se funge su altri compilatori :confused: :
#include<conio.h>
#include<iostream.h>
#include<bios.h>
void main(){
int ca;
clrscr();
ca = _bios_keybrd(_KEYBRD_READ);
if(ca==0x1c0d)cout<<"Hai premuto invio";
else cout<<"NON hai premuto invio ma un altro tasto";
getch();
}
l'invio ha codice ascii 13, quindi basta un bel if(Tastopremuto==13)
beppegrillo
23-12-2005, 13:37
edit :D
duobutch
23-12-2005, 13:56
Grazie mille per le risposte, ma purtroppo mi da questo errore: :confused:
32:2 C:\Programmi\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
3 C:\..... bios.h: No such file or directory.
6 C:\..... `clrscr' undeclared (first use this function)
7 C:\..... `_KEYBRD_READ' undeclared (first use this function)
ecc ecc
anche provando con #include <iostream> (senza .h) non va :doh:
maulattu
23-12-2005, 15:02
Grazie mille per le risposte, ma purtroppo mi da questo errore: :confused:
32:2 C:\Programmi\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
3 C:\..... bios.h: No such file or directory.
6 C:\..... `clrscr' undeclared (first use this function)
7 C:\..... `_KEYBRD_READ' undeclared (first use this function)
ecc ecc
anche provando con #include <iostream> (senza .h) non va :doh:
fai come ti dice wisher, è un metodo standard ;)
frizzo28
23-12-2005, 15:37
Spettacolo!! Grazie wisher del consiglio questo codice funge nn solo co turbo c++ ma pure col dev c++ ed è molto + semplice nn c avevo pensato all'ascii :D
#include<stdio.h>
#include<conio.h>
int main(){
int cara;
cara=getch();
if(cara==13)printf("hai premuto l'ivio");
else printf("Hai premuto un altro tasto");
getch();
}
Ricordatevi che Turbo C non è per niente aderente allo standard...dico questo solo per faro tenere a memoria a chi leggesse questo thread...
Quindi frizzo28, se stai cercando di imparare il C in Turbo C cambia compilatore...ne va di quello che stai imparando...
Per ricavare l'invio basta if(tastopremuto == '\n')...che è portabile su qualsiasi piattaforma...
frizzo28
24-12-2005, 14:17
ah Ok solo che a scuola ci insegnano TC e tt i PC hanno solo quello :cry: Quale compilatore mi consigli?
duobutch
24-12-2005, 14:49
Grazie mille a tutti funziona perfettamente :)
ah Ok solo che a scuola ci insegnano TC e tt i PC hanno solo quello :cry: Quale compilatore mi consigli?
Digli di passare a Dev-C++ o a http://www.codeblocks.org/
Entrambi sono completamente gratuiti e usano il compilatore MinGW32, che è un porting per Windows del compilatore di Linux...
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.