Raised This Month: $32 Target: $400
 8% 

String lengh issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 10-16-2010 , 12:42   String lengh issue
Reply With Quote #1

I want to know how much characters are in use in a string but with not passing str_to_num.

Example :
Code:
new name[32]; if(name > 31) /* Or something like that */
Because I want to copy name (String) to an new array.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 10-16-2010 , 12:51   Re: String lengh issue
Reply With Quote #2

strlen( x )

if( strlen( name) > 31 )

Last edited by dFF; 10-17-2010 at 07:40. Reason: careless...
dFF is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 10-16-2010 , 13:56   Re: String lengh issue
Reply With Quote #3

Quote:
Originally Posted by dFF View Post
strlen( x )

if( strlen( name > 31 ) )
Code:
if( strlen( name ) > 31 )
__________________
Hi.
Kreation is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 10-17-2010 , 02:48   Re: String lengh issue
Reply With Quote #4

Doesn't work:s
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-17-2010 , 03:04   Re: String lengh issue
Reply With Quote #5

Tell us specifically what you are doing

Quote:
Originally Posted by #8 SickneSS View Post
Because I want to copy name (String) to an new array.
According to this statement all you need is to use copy().
__________________
fysiks is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 10-17-2010 , 05:48   Re: String lengh issue
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Tell us specifically what you are doing



According to this statement all you need is to use copy().
Yes but I must check the lengh of the string,because if the player tipes more than 32 lenght,this will be show an print and will give one more chance to the player.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 10-17-2010 , 06:05   Re: String lengh issue
Reply With Quote #7

If you must check the length of some string use strlen()
If you want something to be copied to something else, just use copy, don't freaking worry about lenghts because copy requires a length parameter of the string you're writing to so basically, it's failproof.
__________________
Hunter-Digital is offline
issen1
Member
Join Date: Jan 2010
Old 10-17-2010 , 06:24   Re: String lengh issue
Reply With Quote #8

Quote:
Originally Posted by Hunter-Digital View Post
If you must check the length of some string use strlen()
If you want something to be copied to something else, just use copy, don't freaking worry about lenghts because copy requires a length parameter of the string you're writing to so basically, it's failproof.
He's trying to save a message by a player from the server and if the player's message exceeds the maximum length for his array, he wants to ask the player to enter a new message.

strlen is what you are looking for. What do you mean with "It doesn't work" ?
__________________
greets (:
issen1 is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 10-17-2010 , 06:26   Re: String lengh issue
Reply With Quote #9

I tried the wat of Kreation and dFF and didn't work:s
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
issen1
Member
Join Date: Jan 2010
Old 10-17-2010 , 06:29   Re: String lengh issue
Reply With Quote #10

Quote:
Originally Posted by #8 SickneSS View Post
I tried the wat of Kreation and dFF and didn't work:s
The code of dFF was wrong, but the code of Kreation should work. Show some more code because your mistake is somewhere else.
__________________
greets (:
issen1 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode