Thread: Not able to compare a char variable

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    18

    Not able to compare a char variable [SOLVED]

    First of all, hello everyone.

    I'm pretty much a virgin, here and in programming.

    So the problem is:

    Code:
    do
    	{
    	printf("Introduza o nome do contacto(max. 32 caracteres):\n");
    	getchar();
    	gets(contacto1.nome);
    
    	printf("Introduza o número de telefone:\n");
    	scanf("%d", &contacto1.num);
    
    	printf("Introduza a Data de Aniversário(dd/mm/aaaa):\n"); //É preciso implementar verificação de data correcta
    	for(i=0;i<12;i++)
    	{
    		scanf("%c", &contacto1.bday[i]);
    	}
    
    	printf("Os dados são:\nNome: %s\nNúmero: %d\nData de Nascimento: ", contacto1.nome, contacto1.num);
    	for(i=0;i<12;i++)
    	{
    		printf("%c", contacto1.bday[i]);
    	}
    	printf("\nPretende guardar este contacto?(S\\N)\n");
    	scanf("%c", &o);
    	
    	}while(o!='S' || o!='s');
    when I'm trying to terminate the loop by answering "S" or "s" it doesn't terminate. It just goes on and on, no matter what I input to $o. Can anyone explain me why it doesn't break the loop?

    Thank you and sorry for my english. I'm portuguese as you can see by the piece of code in there.
    Last edited by eidgeare; 12-06-2009 at 01:08 PM.

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Change:
    Code:
    }while(o!='S' || o!='s');
    to
    Code:
    }while(o!='S' && o!='s');
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    18
    Thank you, just realised how stupid I was

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM