Sion Posted December 18, 2007 at 07:34 PM Report Share #155059 Posted December 18, 2007 at 07:34 PM Boas Agora que chegaram as férias pus-me a brincar um bocado com C, so que surgiu-me um problema logo ao inicio: O Programa executa bem, o codigo, segundo o compilador ta correto so que quando insiro uma das opcoes dos 'Cases', neste caso o 'a' , nada aparece no ecra o programa simplesmente passa a frente o código é o seguinte: #include <stdio.h> #include <stdlib.h> int main() { int i; printf("|------------------------------------------------------------|\n"); printf(" ----: a b c d e |\n"); printf("|_____________________________________________________ |\n"); printf(" | 6 |\n"); printf("Prima o respectivo numero para se deslocar a esse lugar\n"); scanf("%d",i); switch (i) { case 'a': printf("|------------------------------------------------------------|\n"); printf(" ----: 2 3 4 5 |\n"); printf("|_____________________________________________________ |\n"); printf(" | 6 |\n"); break; } system("PAUSE"); return 0; } Espero que me possam ajudar, Cumps e obrigado. _________________Cenas pá. Link to comment Share on other sites More sharing options...
saunde Posted December 18, 2007 at 07:51 PM Report Share #155063 Posted December 18, 2007 at 07:51 PM Estás a usar inteiros para o scanf.. e para o i do switch.. e depois tás a usar o caracter a 'a', a menos que o inteiro seja o código do caracter a isso não vai funcionar.. Um blog :Sem Cafeína Link to comment Share on other sites More sharing options...
Sion Posted December 18, 2007 at 08:02 PM Author Report Share #155065 Posted December 18, 2007 at 08:02 PM Brigado pela ajuda, já corrigi essa parte só que agora quando o programa faz scan do valor da variável, e primo enter ele dá erro _________________Cenas pá. Link to comment Share on other sites More sharing options...
saunde Posted December 18, 2007 at 08:10 PM Report Share #155067 Posted December 18, 2007 at 08:10 PM O scanf("%d",i); que estás a fazer está à espera de um int .... se meteres outra coisa .. ele queixa-se... Aqui vai a especificação do scanf : http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html Se quiseres receber um char ... como deve ser o teu caso usas %c ... ou se quiseres uma string .. %s. Um blog :Sem Cafeína Link to comment Share on other sites More sharing options...
Sion Posted December 18, 2007 at 08:16 PM Author Report Share #155072 Posted December 18, 2007 at 08:16 PM Sim, essa parte, já corrigi tudo o problema e que qualquer scanf de qualquer tipo de variável , crasha o meu programa,( e agora que testei, não é so neste programa que crasha nos scanf) _________________Cenas pá. Link to comment Share on other sites More sharing options...
zedlav Posted December 18, 2007 at 08:17 PM Report Share #155073 Posted December 18, 2007 at 08:17 PM codigo correcto. #include <stdio.h> #include <stdlib.h> int main() { char i; printf("|------------------------------------------------------------|\n"); printf(" ----: a b c d e |\n"); printf("|_____________________________________________________ |\n"); printf(" | 6 |\n"); printf("Prima o respectivo numero para se deslocar a esse lugar\n"); scanf("%c",&i); switch (i) { case 'a': printf("|------------------------------------------------------------|\n"); printf(" ----: 2 3 4 5 |\n"); printf("|_____________________________________________________ |\n"); printf(" | 6 |\n"); break; default: break; } return 0; } http://zedlav.dyndns.org Link to comment Share on other sites More sharing options...
Triton Posted December 18, 2007 at 09:27 PM Report Share #155089 Posted December 18, 2007 at 09:27 PM Falta-te o & antes da variável no scanf. <3 life Link to comment Share on other sites More sharing options...
Sion Posted December 18, 2007 at 10:06 PM Author Report Share #155098 Posted December 18, 2007 at 10:06 PM Problema resolvido. Obrigado a todos 😛 _________________Cenas pá. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now