Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Sogou, Yahoo!

Members: 0
Guests: 5
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » General Discussions » Removing names from a list?
Forum Rules | Mark all | Recent Posts

Removing names from a list?
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 11, 2006, 2:37 pm
Go to the top of the page
Go to the bottom of the page

Halcyon
Magician
GroupMembers
Posts187
JoinedApr 12, 2005

Okay, so I'm working on some code for allowing "guests" in your home in SWR. Adding names to the list works fine... Actually REMOVING them is really tripping me up, though. Here's the code:

	if( !str_cmp( arg, "remove" ) )
	{
		strcpy( buf, ch->plr_home->guests );

		buf4 = buf;

		while( *buf4 )
		{
			buf4 = one_argument( buf4, arg );

			if( !nifty_is_name( arg, argument ) )
			{
				sprintf( buf3, "%s ", arg );
				strcat( buf2, buf3 );
			}
		}

		STRFREE( ch->plr_home->guests );
		ch->plr_home->guests = STRALLOC( buf2 );
		send_to_char( "Guest list updated.\r\n", ch );
		return;
	}


Now, if I have a list of say, 3 people, "Samson Remcon Zeno", and suddenly, I don't like Samson anymore cuz he's mean :P, if I do "setguest remove samson"... Samson's place in the string just fills up with garble instead. It's about like what happens when you don't NULL-terminate a string, but... What the hell? What's causing that? Did I do something backwards or something?
       
Post is unread #2 May 11, 2006, 5:04 pm   Last edited May 11, 2006, 5:07 pm by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Try something like this
    if( !str_cmp( arg, "remove" ) )
    {
        buf3 = ch->plr_home->guests;
        buf3 = one_argument( buf3, buf );
        buf2[0] = '\0';
        while( buf && buf[0] != '\0' )
        {
           if( !nifty_is_name( buf, argument ) )
           {
              if( !buf2 || buf2[0] == '\0' )
                 sprintf( buf2, "%s", buf );
              else
                 sprintf( buf2, "%s %s", buf2, buf );
           }
           buf3 = one_argument( buf3, buf );
        }

        STRFREE( ch->plr_home->guests );
        ch->plr_home->guests = STRALLOC( buf2 );
        send_to_char( "Guest list updated.\r\n", ch );
        return;
    }


That should work, note that I havent tested it or anything lol :)
       
Post is unread #3 May 11, 2006, 5:55 pm
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

Look into the empower snippet. I think it has a function to remove a string from a string.
       
Post is unread #4 May 11, 2006, 7:09 pm
Go to the top of the page
Go to the bottom of the page

Halcyon
Magician
GroupMembers
Posts187
JoinedApr 12, 2005

I took your advice, Zeno, and looked the empower snippet up. The author does indeed happen to have a function to strip a string from a string... Ironically, the only difference between his method and the one I used was he properly initialized the string that I didn't. XD

Thanks to both of you, though, appreciate it.
       
Pages:<< prev 1 next >>