Thread

another question :) (Bots)

another question :) // Bots

1  |  

swe

Jul 14, 2003, 2:35pm
hey, i need help breaking up strings in c++, anyone know how to? im making a
bot, that changes the avatars of tourists when they say /avatar # (where #
is the avatar number), how do i get the # as a int? i looked throughtout my
c++ book but couldnt find it anywhere! >_<

thanx, and sorry for being such a n00b :)
-SWE

codewarrior

Jul 14, 2003, 3:04pm
atoi()

[View Quote]

bowen

Jul 14, 2003, 3:15pm
[View Quote] I'm sure that'll get him the number, but, he might have other commands
that use nearly the same format. So it might not work for him.

--
--Bowen--

No of SETI units returned: 30
Processing time: 23 days, 18 hours.
(Total hours: 570)
www.setiathome.ssl.berkeley.edu

andras

Jul 14, 2003, 3:48pm
[View Quote] > hey, i need help breaking up strings in c++, anyone know how to? im making a
> bot, that changes the avatars of tourists when they say /avatar # (where #
> is the avatar number), how do i get the # as a int? i looked throughtout my
> c++ book but couldnt find it anywhere! >_<
>
> thanx, and sorry for being such a n00b :)
> -SWE
>
>

char *l, *chat;
int val;

l=strtok(chat," \t,"); // points to the /avatar and replaces the " " (or comma or tab) with the NULL character
l=strtok(NULL," \n"); // points to the number and replaces the " " (or comma or tab or newline) with the NULL character
// effectively l will hold only the second token in the chat line
val=atoi(l);


-------------------------
Syntax

#include <string.h>
char *strtok(char *s1, const char *s2);

Description

Searches one string for tokens, which are separated by delimiters defined in a second string.
strtok considers the string s1 to consist of a sequence of zero or more text tokens, separated by spans of one or more characters from the separator string s2.
The first call to strtok returns a pointer to the first character of the first token in s1 and writes a null character into s1 immediately following the returned token. Subsequent calls with null for the first argument will work through the string s1 in this way, until no tokens remain.
The separator string, s2, can be different from call to call.

Note: Calls to strtok cannot be nested with a function call that also uses strtok. Doing so will causes an endless loop.

Return Value

strtok returns a pointer to the token found in s1. A NULL pointer is returned when there are no more tokens.
------------------------------
--
Andras
"It's MY computer" (tm Steve Gibson)

swe

Jul 14, 2003, 5:23pm
thanx alot :) greatly appreciated :)

-SWE

[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn