Originally Posted by
Salem
Well you can't just use scanf(), because you're trying to treat one of the inputs as optional.
Originally Posted by
vikasvijayan
by using the single scanf(),you cannot terminate the pgm by inputting one zero
Code:
#include<stdio.h>
int main( void )
{
int done = 0;
do
{
int a, b;
printf( "enter #,# or 0 to exit: " );
fflush( stdout );
switch( scanf( "%d,%d", &a, &b ) )
{
case 2: printf( "a: %d, b: %d\n", a, b ); break;
case 1: if( a == 0 ) { done = 1; break; }
default: /* error */ scanf( " %*[^\n]%*c" );
}
}
while( !done );
return 0;
}
:eyebrow:
Edit - You can still make it slightly amiss with your input, but it doesn't break.
Quzah.