what is buffer? or buffer safe??
This site helped me out a fair bit
hope it will help others too.
- - fUnKy F3m@le - -
Input (and output for that matter) is handled one of two ways:Originally posted by hermit
what is buffer? or buffer safe??
buffered, or unbuffered.
With buffered input, like with scanf, nothing happens until you hit "enter". That is to say:
printf("Enter a character and hit enter: ");
scanf("%c%*c", &myvar );
When the above line executes, I can type all I want:
dfs;ljfadl';klfj;lfdlksfa;lfdj;fdljfds;
And what happens is that it reads the 'd', and the second %c will ignore the 'f', but the rest is left 'buffered', meaning that it is sitting there on the input stream waiting for me to do something with it.
This is why your scanf call "didn't work right" when you tried earlier.
The above code would work right, if you had simply typed the letter d then hit enter.
The second of my two examples uses some advanced (not really advanced, just rarely used in comparison) features of scanf to skip all the reamining input up to and including the newline (enter key).
That is what I meant by it being "buffer safe". It doesn't leave crap in the input buffer, and doesn't require any special code to clear the remaining text.
Quzah.
Hope is the first step on the road to disappointment.
that is very helpful ! thanks quzah
very well written . . u should consider being a lecturer
- - fUnKy F3m@le - -
Don't encourage himOriginally posted by hermit
u should consider being a lecturer
Jason Deckard
much better than my tutor at uni BORING BORING,
alot of self studying to do
But, thank you again . .
- - fUnKy F3m@le - -