Author Topic: Byte pointer issue  (Read 111 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 148
Byte pointer issue
« on: October 10, 2018, 04:18:28 AM »
Hello Charles

i have modified your program in the O2 forum
https://www.oxygenbasic.org/forum/index.php?topic=1781.msg19343;topicseen#msg19343

but did not get correct results.

Code: [Select]
' program to print a byte character of a string
' it prints out the Ascii code of that character
' Prin_OneChar.o2bas

$ filename "Prin_OneChar.exe"
 uses rtl64

wchar w[11] = "1234567890"
byte b at strptr w


print    " 1st  position  byte  Ascii  : "    b[1]   "      Actual character : "   chr(b[1])            '  display 1
print    " 5th position   byte  Ascii  : "    b[5]   "      Actual character : "   chr(b[5])           '  display 3  ??  should be 5

print    " 9th position   byte  Ascii  : "    b[9]   "      Actual character : "   chr(b[9])        '  display  5 ??  should be  9
print    " 11th position   byte  Ascii  : "    b[11]   "      Actual character : "   chr(b[11])     ' display  6  ??  should be 0


for example,  b[5]  would display 3  instead of 5

while  b[9]  would display 5 instead of 9

maybe i'm wrong in the code,  what would be better code to resolve this?

Thanxx


Offline Josť Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2471
    • Josť Roca Software
Re: Byte pointer issue
« Reply #1 on: October 10, 2018, 06:30:26 AM »
Change

byte b at strptr w

to

word b at strptr w

Unicode uses 2 bytes (a word), not single bytes.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 148
Re: Byte pointer issue
« Reply #2 on: October 10, 2018, 07:28:13 AM »
Thanxx a lot Jose

You are very sharp !