Author Topic: Help With Pointers and Strings  (Read 4479 times)

0 Members and 1 Guest are viewing this topic.

Offline SnowLeopard

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Help With Pointers and Strings
« on: November 15, 2010, 06:49:47 pm »
Hi I was wondering if someone could help me out with this. I am having problems working with strings and Copy to display a certain string depending on what the value is. What am i doing wrong? Sorry if this is kind of n00bish but i just can't figure it out.
Code: [Select]
.CONV
8→A
".01    "→Str1
"1      "
"5      "
"10     "
"25     "
"50     "
"75     "
"100    "
"200    "
"300    "
"400    "
"500    "
"750    "
"1000   "
"5000   "
"10000  "
"25000  "
"50000  "
"75000  "
"100000 "
"200000 "
"300000 "
"400000 "
"500000 "
"750000 "
"1000000"
[0000000000000000]→Str2
Copy(Str1+A,Str2,8)
Output(0,0,Str2)
Pause 5000

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Help With Pointers and Strings
« Reply #1 on: November 15, 2010, 06:59:25 pm »
Hmmmm that looks like it should work, what type of errors are you getting?
« Last Edit: November 15, 2010, 07:07:43 pm by Builderboy »

SirCmpwn

  • Guest
Re: Help With Pointers and Strings
« Reply #2 on: November 15, 2010, 07:00:24 pm »
Add another 00 to Str2 and see if it works.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Help With Pointers and Strings
« Reply #3 on: November 15, 2010, 07:03:58 pm »
Oh, I see. It's because when you store a string to a pointer, like in your code ".01    "→Str1, Axe actually adds an extra zero after it (because in assembly, that's how the calc knows the string has ended). So change that line to []→Str1:".01    " and it should work.

Also, add an extra zero to Str2 for padding, as SirCmpwn said.
« Last Edit: November 15, 2010, 07:04:55 pm by Deep Thought »




SirCmpwn

  • Guest
Re: Help With Pointers and Strings
« Reply #4 on: November 15, 2010, 07:08:10 pm »
He actually doesn't need to do the first part, storing the extra zero alone should work.  Although his string will start at 9, not 8.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Help With Pointers and Strings
« Reply #5 on: November 15, 2010, 07:10:38 pm »
You also need to change the copy function to use a length of 7 or else you will copy one extra character from the next string

Offline SnowLeopard

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Re: Help With Pointers and Strings
« Reply #6 on: November 15, 2010, 07:25:50 pm »
Ok thanks guys, i got it working. For some reason I thought that the ending quotation mark counted as an extra byte.
Code: [Select]
.CONV
For(B,0,26)
B*7→A
[]→Str1
".01    "
"1      "
"5      "
"10     "
"25     "
"50     "
"75     "
"100    "
"200    "
"300    "
"400    "
"500    "
"750    "
"1000   "
"5000   "
"10000  "
"25000  "
"50000  "
"75000  "
"100000 "
"200000 "
"300000 "
"400000 "
"500000 "
"750000 "
"1000000"
[000000000000000000]→Str2
ClrHome
Copy(A+Str1,Str2,7)
Output(0,0,Str2)
Pause 500
End

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Help With Pointers and Strings
« Reply #7 on: November 15, 2010, 07:28:14 pm »
Nope :) And btw if you are using a copy with a length of 7, you can make your Str2 one byte shorter

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Help With Pointers and Strings
« Reply #8 on: November 15, 2010, 10:22:07 pm »
By the way welcome on the forums. I hope you have fun coding in Axe, for calculators and on the forums. :)