Thread: Flushing Out fflush(stdin);

  1. #16
    Registered User
    Join Date
    Nov 2007
    Quote Originally Posted by matsp View Post
    The -entry is there to give you an index of the newline, rather than the ADDRESS of thre newline, which is what the strchr() returns. It inserts a NUL (note a single L) at the newline location in the string.
    I realize I could do it either of the other two ways you suggested but I'd like to figure out what the -entry means in that line. What's an "index" in this case? I'm thinking in terms of a minus operator which really doesn't make sense to me in this instance. Thanks again.

    (Last question in this thread I swear )


  2. #17
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    An index is a postion in an array. If you consider entry[0], "entry" is the array and "0" is the index. With entry[2], that references the 3rd element in the array. And so on.

    "entry" is the array, but really, it is the address (in memory) of the array.

    strchr() return the address of the specified character. It is illegal to use an address (per se) as an index. So, to calculate an index, I subtracted the start of the array address ("entry") from the address of the newline character in "entry". Address2 - address1 = an integer, which can be used as an index.


  3. #18
    Registered User
    Join Date
    Nov 2007
    Rawk. This thread helped a lot. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. fread/fwrite
    By chopficaro in forum C Programming
    Replies: 6
    Last Post: 05-11-2008, 01:48 AM
  3. Searching Into Files
    By St0rM-MaN in forum C Programming
    Replies: 12
    Last Post: 04-26-2007, 09:02 AM
  4. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  5. Linked List Need Help Urgent
    By ykchua in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:57 PM