Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: scanf(..) Message-ID: <1989Jun4.064142.13829@utzoo.uucp> Organization: U of Toronto Zoology References: <225800176@uxe.cso.uiuc.edu> Date: Sun, 4 Jun 89 06:41:42 GMT In article <225800176@uxe.cso.uiuc.edu> burkie@uxe.cso.uiuc.edu writes: >scanf("%c", &c); >... >I find that sometimes the program above doesn't stop >at the scanf to wait for input, esp. if there are other >input, print etc. statements.. Do I have to flush some >buffers etc for this to work properly? There is often buffering of input; in particular, many systems (all Unix systems, in particular) essentially do input a line at a time regardless of whether you're only asking for it a character at a time. Actually inputting a character at a time is complicated and somewhat system-dependent; queries on how it should be done should go to comp.unix.questions (or other appropriate operating-system group), not comp.lang.c. >while (...) { > scanf("%d, %d", &x, &y); > >if I type 'a' on the keyboard, why >does the loop keep running, skipping over the scanf ? Because the scanf is failing. You should NEVER NEVER NEVER do a scanf without checking the returned value to find out whether it worked. -- You *can* understand sendmail, | Henry Spencer at U of Toronto Zoology but it's not worth it. -Collyer| uunet!attcan!utzoo!henry henry@zoo.toronto.edu