Compare nums
Hi.I want to compare the name length of players from server and print the lowest name...how can i make that ?!
Note:I know how to get the name length, but dunno how to compare the nums... Thanks. |
Re: Compare nums
Loop through them, comparing the strlen of the current one to the shortest found so far.
Save the shortest name and its length. Do you also need to know which user it was? PHP Code:
(using id-1 is a total waste of time, [33] PWNS ) |
Re: Compare nums
Humm...yeah i need to print shortest name...but i think i got it :D
Code:
Dumb code. |
Re: Compare nums
Possibly.
It's much harder to judge if something will work than write it :-D Try it :-D EDIT: And there's no point to strlen ShortestName every iteration - you can just save it. No, it won't work. If only because you got you > and < the wrong way around ... That, and shortestname starts off empty. So its strlen is 0. So no other string can be shorter :-D Re-EDIT: this: PHP Code:
I only changed a little - mainly swapping < for >, initialising shNameLen as 9999 and saving ShNameLen between iterations, rather than getting it each time. |
Re: Compare nums
Yeah lol, and i've puted the wrong sybol ">" , doh...i will try you'rs! :P
|
Re: Compare nums
My earlier code was slightly wrong.
For some unknown reason I thought I'd try using a 32 cell array, which threw everything to hell. It's now right though - both codes I posted return or log the right name. |
Re: Compare nums
Yup, second one work fine and is optimized! Thanks :D
|
| All times are GMT -4. The time now is 16:13. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.