0
#include<stdio.h>
#include<conio.h>
void main()
{
    char a, b;
    scanf("%c",&a);
    if(a=='n')
    {
        scanf("%c",&b);
        if(b=='n')
        {
            printf("sucessful");
        }
    }
    else
        printf("fail");
    getch();
}

problem with the code reading 'b' variable. Why can't it read 'b' variable. It will work when the datatype is int, or float. Please help me with the logic.

mkobit
  • 43,979
  • 12
  • 156
  • 150
  • What exactly did you type in? I'm sure the code is working exactly as you wrote it, even if that's not what you meant it to do. But you forgot to tell us what you meant. – Ben Voigt Feb 18 '15 at 04:38

1 Answers1

0

You can use do while loop to figure out this. 'do' runs 0 or more times while "while" holds condition. This can help you.

Kashif
  • 439
  • 6
  • 10
  • thank you for responding to my question. I have found the solution to the problem it works when we use %s instead of %c using scanf(). BUt still I am stuck with the logic behind this... can anyone help me why %c does not work and why %s works fine... If anyone helps me i would me more than thankful.... – Madan Pandey Feb 24 '15 at 06:03
  • There is a type conversion required in your if statement. Please go through this link. http://stackoverflow.com/questions/1010330/c-comparison-char-and-int – Kashif Feb 24 '15 at 07:53