NWY Posted September 18, 2006 at 08:32 PM Report Share #51438 Posted September 18, 2006 at 08:32 PM Estava a dar revisoes quando me deparei com esta situação. #include <stdio.h> main() { char nome[30]; do { printf("Nome:"); gets(nome); puts(nome); } while(nome!="SAIR"); printf("Sair..."); system("pause"); } Era suposto sair quando introduzi-se "SAIR"...mas não sai! Que frustração! Cumprimentos. Link to comment Share on other sites More sharing options...
Mythos Posted September 18, 2006 at 08:39 PM Report Share #51439 Posted September 18, 2006 at 08:39 PM Muda o while para algo do género: while( strcmp( nome, "SAIR" ) ); edit: tinha posto o ! no strcmp quando na realidade isso ia fazer sair do loop sempre que se inserisse algo diferente de "SAIR" ( o strcmp devolve 0 quando as strings são iguais ) Link to comment Share on other sites More sharing options...
Hipnoted Posted September 18, 2006 at 08:40 PM Report Share #51441 Posted September 18, 2006 at 08:40 PM Para comparar strings tens de usar a função strcmp (string compare). Ou seja, em vez de: while(nome!="SAIR"); tens de pôr while(strcmp(nome,"SAIR")!=0) "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência" Link to comment Share on other sites More sharing options...
NWY Posted September 19, 2006 at 08:20 PM Author Report Share #51654 Posted September 19, 2006 at 08:20 PM era isso, obrigado.Cumps. 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