Struct File and array problem Please help

This is a discussion on Struct File and array problem Please help within the C Programming forums, part of the General Programming Boards category; Originally Posted by caroundw5h you could make it even more compact Code: #define FLUSH while ( (getchar() ! = '\n') ...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by caroundw5h View Post
    you could make it even more compact
    Code:
    #define FLUSH while ( (getchar() ! = '\n') )
    and then call FLUSH whenever you want to clean out the buffer.
    And what will happen to this more compact code when stdin will be redirected to read from file and actually hits the EOF?

    Getting code shorter by adding more bugs is not a good way to program
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by vart View Post
    And what will happen to this more compact code when stdin will be redirected to read from file and actually hits the EOF?
    where in his code is he redirecting stdin to read from a file (unless you mean waiting for the EOF to to be hit via the terminal)? His objective was to get the junk out of the input buffer and clean it up. To that end he can read up to the '\n' after each input. Sure he could add the EOF to that as well to that macro, just seems like overkill IMHO.

    Getting code shorter by adding more bugs is not a good way to program
    I agree whole heartedly, the objective on my part wasn't to offer a quick fix and forget potential future issues, it was to generate compact code for the task at hand. Why declare a long, when a int with do?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    Quote Originally Posted by caroundw5h
    where in his code is he redirecting stdin to read from a file (unless you mean waiting for the EOF to to be hit via the terminal)?
    The redirection can happen from the terminal/console/command prompt, not just the code.

    Quote Originally Posted by caroundw5h
    His objective was to get the junk out of the input buffer and clean it up. To that end he can read up to the '\n' after each input. Sure he could add the EOF to that as well to that macro, just seems like overkill IMHO.
    vart's point is about correctness. It might be a little paranoid, but the "overkill" will have no impact on performance anyway, and remains readable.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

Similar Threads

  1. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 04:19 AM
  2. File I/O problem for dynamically allocated struct array
    By veecee in forum C++ Programming
    Replies: 2
    Last Post: 05-05-2006, 09:28 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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