Originally Posted by
vart
you haven't asked and OP haven't said if it is Windows or Unix
you do not check return value of scanf...
you do not guard against buffer overrun in scanf
and void main - read FAQ why you should not use it
Hi Vart, I am using Unix.
Here are portions of my code:
Code:
void* scan(char* buffer)
{
return fgets(buffer, MAX_BUFFER_SIZE, stdin);
}
void dump_scanf(FILE* fp)
{
int ch;
while( (ch = fgetc(fp)) != EOF && ch != '\n' );
}
Code:
int x,y;
char extra;
char* buffer = (char *)malloc(sizeof(char)*MAX_BUFFER_SIZE);
printf("Your input: ");
void* scan_ptr = scan(buffer);
if(scan_ptr)
{
r = sscanf(buffer, "%d %d%c", &x, &y, &extra);
printf("feof(stdin)=%d\n", feof(stdin));
if(strlen(buffer) > 6)
{
dump_scanf(stdin);
}
}
Code:
Your input: 2 2^D
feof(stdin)=0
^D is shown when I press the combination keys Ctrl+D. How do I read that?