Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Aliases
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Fri 24 May 2002 04:34 AM (UTC) Amended on Fri 24 May 2002 05:40 AM (UTC) by Nick Gammon
|
Message
| I downloades the alias snippet from Samson's page (alsherok.net), and it works nicely, but I am trying to make it so that if a player makes an alias with a semicolon in it, it will interpret it as more then one command, and first execute the command before the semicolon then try doing the one after the semicolon. Here is what I've come up with so far, and it isn't working too well, if you have any suggestions how I can get it to work.
char *x;
char arg2[MAX_INPUT_LENGTH];
int y;
y = 0;
x = arg;
for( x = arg; *x != '\0'; x++ )
{
if(*x == ';')
{
y = 0;
interpret(ch, arg2);
strcpy(arg2, arg);
arg2 == NULL;
return TRUE;
}
else
{
arg2[y] = *x;
y++;
}
}
This is only the code meant to look for a semicolon, but it doesn't seem to work properly. I'm not sure how clear I was, I can explain again if you can't understand what I want to do.
-Jay | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 24 May 2002 05:48 AM (UTC) |
Message
| For a start, you aren't terminating the new string with a null byte. Second, you are returning after finding a semicolon, which won't help. Third, the line "arg2 == NULL;" won't achieve much.
Try something like this:
char *x;
char arg2[MAX_INPUT_LENGTH];
int y;
y = 0;
x = arg;
for( x = arg; *x != '\0'; x++ )
{
if(*x == ';')
{
arg2[y] = 0; // terminate arg2
interpret(ch, arg2); // interpret it
y = 0; // start at start of arg2 again
} // end of semicolon found
else
arg2[y++] = *x; // copy it
} // end of for loop
// do final one after the semicolon
arg2[y] = 0; // terminate arg2
if (arg2 [0] != '\0') // if not empty
interpret(ch, arg2); // interpret it
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Reply #2 on Mon 27 May 2002 02:24 AM (UTC) Amended on Mon 27 May 2002 03:37 AM (UTC) by Nick Gammon
|
Message
| Thanks, but there was a slight error in it that I found for all those who want to use this code, change:
if(*x == ';')
{
y = 0;
interpret(ch, arg2);
strcpy(arg2, arg);
arg2 == NULL;
return TRUE;
}
to:
if(*x == ';')
{
y = 0;
if (arg2 [0] != '\0') // if not empty
interpret(ch, arg2);
strcpy(arg2, arg);
arg2 == NULL;
return TRUE;
}
In case a person puts two semicolons in a row this will make sure it doesn't turn up as a null char.
-Jay | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 27 May 2002 03:40 AM (UTC) |
Message
| I'm surprised it works with this:
strcpy(arg2, arg);
arg2 == NULL;
First, I don't think the strcpy will achieve much, and the line:
arg2 == NULL;
definitely won't, because that is just a test (== means "is equal to").
That line doesn't change anything, it just tests to see if arg2 is NULL, and throws away the result. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Reply #4 on Thu 30 May 2002 01:56 AM (UTC) |
Message
| I made a mistake and copied my original code, I meant to say in your code there is a slight error that if a person puts two semicolons in a row it will come out with a null argument, so to fix it, change:
if(*x == ';')
{
arg2[y] = 0; // terminate arg2
interpret(ch, arg2); // interpret it
y = 0; // start at start of arg2 again
} // end of semicolon found
to:
if(*x == ';')
{
arg2[y] = 0; // terminate arg2
if (arg2 [0] != '\0') // if not empty
interpret(ch, arg2); // interpret it
y = 0; // start at start of arg2 again
} // end of semicolon found
Basically just adding a check to make sure arg2 is not empty before interpreting it.
Thanks,
Jay | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
15,658 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top