lost

This is a discussion on lost within the C Programming forums, part of the General Programming Boards category; I am trying to write a loop that will display the 20 most recent calculations inputed and display them. When ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    lost

    I am trying to write a loop that will display the 20 most recent calculations inputed and display them. When it loops the 21st time, I need it to kick the first value out and move everything else up. I was thinking of using a for loop to do this but I am unsure of how to start it.

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    It sounds like you want to use a circular buffer, which overwrites from the beginning when it gets full. To accomplish this, just index the array modulo the array size and make sure you don't overwrite anything you still need.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Why didn't you keep this with your original thread in which I suggested a circular linked list?
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The getting lost and walking in circles
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 05-07-2008, 09:53 AM
  2. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 07:13 PM
  3. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 05:18 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 12:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 02:19 PM

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