Thread: i have infinite loops. why?

  1. #16
    Registered User hermit's Avatar
    Join Date
    Apr 2002
    Posts
    213
    what is buffer? or buffer safe??
    - - fUnKy F3m@le - -

  2. #17
    Registered User hermit's Avatar
    Join Date
    Apr 2002
    Posts
    213

    helpful FAQ

    This site helped me out a fair bit

    hope it will help others too.
    - - fUnKy F3m@le - -

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by hermit
    what is buffer? or buffer safe??
    Input (and output for that matter) is handled one of two ways:
    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.

  4. #19
    Registered User hermit's Avatar
    Join Date
    Apr 2002
    Posts
    213

    thanks quzah

    that is very helpful ! thanks quzah
    very well written . . u should consider being a lecturer
    - - fUnKy F3m@le - -

  5. #20
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633

    Re: thanks quzah

    Originally posted by hermit
    u should consider being a lecturer
    Don't encourage him
    Jason Deckard

  6. #21
    Registered User hermit's Avatar
    Join Date
    Apr 2002
    Posts
    213

    Thumbs up quzah should be a tutor

    much better than my tutor at uni BORING BORING,
    alot of self studying to do

    But, thank you again . .
    - - fUnKy F3m@le - -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Infinite Loops in C
    By DaniiChris in forum C Programming
    Replies: 8
    Last Post: 07-06-2008, 12:21 PM
  2. Infinite While Loops Question
    By hern in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2005, 07:27 PM
  3. please help, infinite loops!
    By HybridM in forum C++ Programming
    Replies: 18
    Last Post: 01-14-2003, 09:27 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM