Trouble with assignment in C

This is a discussion on Trouble with assignment in C within the C Programming forums, part of the General Programming Boards category; Try calling this function after every scanf call. You should probably get rid of this problem. Code: void clr_ln_buffer( void ...

  1. #16
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Try calling this function after every scanf call. You should probably get rid of this problem.

    Code:
    void clr_ln_buffer( void )
    {
         int c;
         
         while( ( ch = getchar() ) != EOF && ch != '\n' );
    }
    It does the same job, like what other have been saying.

    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  2. #17
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    try to encode/decode 1234
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    @ssharish2005: I imagine that's what the OP's eat_newline() function ended up looking like. Oh, and by the way, half the time your code uses "c" and the other half "ch".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. trouble with assignment, vectors..
    By bluegoo06 in forum C++ Programming
    Replies: 6
    Last Post: 11-16-2005, 02:43 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21