0
#include<stdio.h>
int main()
{   


    int a, b, c, d, e, f, r=0; 
    r=scanf("%d %d %d %d %d %d\n", &a, &b, &c, &d, &e, &f);
    if(r==6)
    {
        printf( "Hello" );
    } 
    else
    {
        printf( "BOOM!!\n" );
        printf("The bomb has blown up");
    }

}

I want the scanf to take only few inputs < 6 and jump to the else part and execute it.

  • You can, just type something that is not numbers and press enter. – Iharob Al Asimi Feb 28 '18 at 18:13
  • Read a _line_ of user input into a _string_ with `fgets()`, then parse it for `int`. – chux - Reinstate Monica Feb 28 '18 at 18:13
  • Just enter `coderredoc` and it would fail. (Anything not a number you can put and press enter - it would fail. – user2736738 Feb 28 '18 at 18:13
  • 2
    Note that the trailing newline in the format string forces `scanf()` to keep reading until it gets a non-white-space character in the input after the 6th number. – Jonathan Leffler Feb 28 '18 at 18:17
  • Do you really have problems with getting the else part executed? I feel that the idea of this is that it actually is meant to be the *easy* part. Can you describe what you do that gets the "then" part executed? – Yunnosch Sep 17 '18 at 06:59

0 Answers0