Thread: Loop to mark a string as NULL will not work.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    28

    Loop to mark a string as NULL will not work.

    Sorry, I needed to delete this post.
    Last edited by m88g88; 02-21-2010 at 08:06 PM. Reason: To prevent my work for being perceived as plagerised

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have a couple of options:

    1. Copy everything from later elements over top of the one before it to "delete"; keep a counter of how many slots you are actually using.
    2. Simply mark it as 'deleted', and ignore it.

    An example of the latter:
    Code:
    void showsong( int s )
    {
        if( s > -1 && s < 99 && songs[ s ].track[ 0 ] )
        {
             ...print each element...
        }
    }
    
    void deletesong( int s )
    {
        if( s > -1 && s < 99 && songs[ s ].track[ 0 ] )
        {
            /* mark this as unused by setting the spot we check as 0 */
            songs[ s ].track[ 0 ] = 0;
        }
    
    }
    Now, replace where you keep just randomly printing the song without checking to see if it's deleted, with the show function above, calling it with the loop counter of the element to print. Add in the delete function above when you want to mark a track as deleted. Pretty simple stuff. You could even:
    Code:
    int emptysong( int s )
    {
        if( s > -1 && s < 99 && songs[ s ].track[ 0 ] == 0 )
            return 1;
    
        return 0;
    }
    3. You could use a linked list, which actually does remove slots in the song list.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM