gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfxgfx
 
Members, please note that our guidelines are located here.
 
gfx gfx
gfx
484576 Posts in 28410 Topics by 2464 Members - Latest Member: austinrobert February 28, 2020, 04:32:25 PM
*
gfx* Home | Help | Calendar | Login | Register | gfx
gfx
The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  strlen issue
gfx
gfxgfx
 

Author Topic: strlen issue  (Read 1131 times)

Offline Khatuni

  • Executive
  • ***
  • Posts: 1,007
    • View Profile
strlen issue
« on: December 30, 2010, 04:25:42 PM »
The following script returns a 0 for me. If I change 256 into 255 or below, it returns 5, which was my intention. 256 or above returns 0. I'm baffled...  any ideas?

new smurf[8] = {256, 4640, 4640, 4640, 4608}
ValueText(strlen(smurf), 100, 130)

Offline Luke

  • Regimental
  • ****
  • Posts: 1,823
    • View Profile
Re: strlen issue
« Reply #1 on: December 30, 2010, 04:56:18 PM »
my guess is that strlen treats it as a packed string, and when it's 256 the first byte (8 bits) is 0, thus ending the string.

http://www.compuphase.com/pawn/String_Manipulation.pdf
http://calc.50x.eu/?size=4&dec=256

Offline Khatuni

  • Executive
  • ***
  • Posts: 1,007
    • View Profile
strlen issue
« Reply #2 on: December 30, 2010, 06:16:07 PM »
Ok, so I'm not supposed to use strlen for arrays of non-Ascii values? Is there a simple method or function to return the length of such an array (like what I wanted in the example)?

The only thing I can think of right now is to check for every value of the string whether it's above 0, until I find one that's 0. If no simple function exists for this, I should write one.

Offline KingOfHumans

  • Messiah
  • ******
  • Posts: 17,866
    • View Profile
Re: strlen issue
« Reply #3 on: December 30, 2010, 08:11:15 PM »
Tested different functions and it looks like your only option may be a loop.

Offline Luke

  • Regimental
  • ****
  • Posts: 1,823
    • View Profile
Re: strlen issue
« Reply #4 on: December 30, 2010, 09:55:29 PM »
Ok, so I'm not supposed to use strlen for arrays of non-Ascii values? Is there a simple method or function to return the length of such an array (like what I wanted in the example)?
yeah strlen is just for strings, but the function itself is just "for (c = 0; array[c] && c < sizeof array; c++){}".

Code: [Select]
// This is a more actual version of strlen but the above code will do for your problem.
strlen(array[], s = sizeof array)
{
new c = 0;
if (array[c] > 0xff)
for (c = 0; array{c} && c<s; c++){}
else
for (c = 0; array[c] && c<s; c++){}
return c;
}


The Gaming Universe  |  The Archives  |  Archived Projects  |  Open Zelda  |  OZ Help (Moderator: red_team316)  |  strlen issue
 

gfxgfx
gfx
SMF 2.0.17 | SMF © 2019, Simple Machines Page created in 0.176 seconds with 21 queries.
Helios Multi © Bloc
gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!
anything