Originally Posted by
BillyTKid
You dont know what i mean.
If a user put more than BUFSIZ-1 characters in inputbuffer, fgets keeps the '\n' and a next inputread will ignored.
Why would it ignore it?
Code:
#include<stdio.h>
#undef BUFSIZ
#define BUFSIZ 5
int main( void )
{
char buff[BUFSIZ];
int a, b;
printf( "format is #,#\ngo:\n" );
while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
if ( sscanf(buff,"%d,%d", &a, &b ) == 2 ) {
// success
printf( "a: %d, b: %d\n", a, b );
} else
if ( sscanf( buff, "%d", &a ) == 1 && a == 0 ) {
// just a 0 on a line by itself - exit
break;
} else {
// something else
printf( "something else:\'%s\'\n", buff );
}
}
return 0;
}
Try it.
Quzah.