Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: SnowLeopard on November 15, 2010, 06:49:47 pm

Title: Help With Pointers and Strings
Post by: SnowLeopard 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
Title: Re: Help With Pointers and Strings
Post by: Builderboy on November 15, 2010, 06:59:25 pm
Hmmmm that looks like it should work, what type of errors are you getting?
Title: Re: Help With Pointers and Strings
Post by: SirCmpwn on November 15, 2010, 07:00:24 pm
Add another 00 to Str2 and see if it works.
Title: Re: Help With Pointers and Strings
Post by: Deep Toaster 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.
Title: Re: Help With Pointers and Strings
Post by: SirCmpwn 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.
Title: Re: Help With Pointers and Strings
Post by: Builderboy 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
Title: Re: Help With Pointers and Strings
Post by: SnowLeopard 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
Title: Re: Help With Pointers and Strings
Post by: Builderboy 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
Title: Re: Help With Pointers and Strings
Post by: DJ Omnimaga 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. :)