This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
WhiteDwarf


Newbie


Joined: 10 Nov 2003
Posts: 19

Posted: 20 Nov 2003 02:41:52 am    Post subject:

How could you write a strlen function.... i was thinking some how storing each value place in a list and then refering to the number of elements as a variable or something, but i wouldnt know how to do sometihng like that...and also like the same function to find the number of value places in a number for instance for a dec2hex(); something like

a = user input;
n = strlen(a-1);

dec2hex(a) = a/16^n->a
Back to top
Arcane Wizard
`semi-hippie`


Super Elite (Last Title)


Joined: 02 Jun 2003
Posts: 8993

Posted: 20 Nov 2003 09:39:40 am    Post subject:

strlen = length(string) -> [2ND],[CATALOG],[L], scroll down

intlen = log(int)+1 (int=0=error)

A = user input
N = log(A)+1

dec2hex(A) = A/16^(log(A)+1)->A

EDIT: I just took it all for pseudo-code, but are you sure you're in the right forum?

C++ (not tested, written from memory)

Code:
int strlen(char * a) {
  x=0;
  while ((a[x] != '\n') && (a[x] != '\0')) { x++; }
  return x;
}


Last edited by Guest on 20 Nov 2003 09:43:20 am; edited 1 time in total
Back to top
sgm


Calc Guru


Joined: 04 Sep 2003
Posts: 1265

Posted: 20 Nov 2003 01:07:14 pm    Post subject:

Arcane Wizard wrote:

Code:
int strlen(char * a) {
  x=0;
  while ((a[x] != '\n') && (a[x] != '\0')) { x++; }
  return x;
}


Code:
int strlen( char * );

int strlen( char *a )
{
    int x = 0;

    while( (a[x] != '\n') && (a[x] != '\0') )
        x++;

    return x;
}


Just so it's easier to read, you understand. :)


And just for fun:

Code:
int strlen(char *a)
{
    asm {
        les    di, a        ; Probably should be lds si, a — can't remember.
        xor    cx, cx
        mov    al, cl
        repne  scasb
        neg    cx
        mov    ax, cx       ; Assuming that results are returned in AX.
    }

/* Might need to push/pop some registers */
}
Back to top
WhiteDwarf


Newbie


Joined: 10 Nov 2003
Posts: 19

Posted: 20 Nov 2003 08:27:35 pm    Post subject:

You can store letters in a list right? like this

{"A", "B", "C", "D","E","F"}-> listA


or would i have to store that into a string, i want to be able to refer to each letter as a location in the list so
Disp listA(3) = "C"
Back to top
JacobdeHaan


Member


Joined: 10 Jul 2003
Posts: 165

Posted: 20 Nov 2003 08:34:01 pm    Post subject:

You can't do that. But by using the sub funcion, you can achieve the same result.

Example:

Code:
sub("ABC",2,1      //this returns the second character in the string, and only one of them
Back to top
WhiteDwarf


Newbie


Joined: 10 Nov 2003
Posts: 19

Posted: 20 Nov 2003 09:47:58 pm    Post subject:

lol coding is very frusterating, it seems the more frusterated i get the less i can think and try and think rationally about debuggin, i'm tryin to write a dec 2 hex program

here's what i have, i bet 20 bucks i'm making it alot harder than need be lol


Code:
 
Input A
: iPart(log(A->B
:  For(X,0,B,1
: iPart(A/16->D
: fPart(A/16->->C
: C*16->C
: If C>9: Then
: Disp sub("ABCDEF",C-9,1
: End
: If C<=9: Then
: Disp C
: End
: If 9<D<16: Then
: Disp sub("ABCDEF",D-9,1
: End
: If D<10: Then
: Disp D
: D->A
: End
: End



Is it ok to do this "9<D<16"? or would u use 9<D and D<16 or somthin
Back to top
Darth Android
DragonOS Dev Team


Bandwidth Hog


Joined: 31 May 2003
Posts: 2104

Posted: 21 Nov 2003 12:18:10 am    Post subject:

yup.
counts up to 65536:
[code]DelVar CDelVar DDelVar EDelVar FCLrHome
Input "Dec:",A
"0123456789ABCDEF->Str1
For(B,1,A
C+1->C
If C=16
Then
DelVar CD+1->D
End
If D=16
Then
DelVar DE+1->E
End
If E=16
Then
DelVar EF+1->F
End
Output(1,1,sub(Str1,F+1,1
Output(1,2,sub(Str1,E+1,1
Output(1,3,sub(Str1,D+1,1
Output(1,4,sub(Str1,C+1,1
Back to top
Darth Android
DragonOS Dev Team


Bandwidth Hog


Joined: 31 May 2003
Posts: 2104

Posted: 21 Nov 2003 12:18:43 am    Post subject:

yup.
counts up to 65536:

Code:
DelVar CDelVar DDelVar EDelVar FCLrHome
Input "Dec:",A
"0123456789ABCDEF->Str1
For(B,1,A
C+1->C
If C=16
Then
DelVar CD+1->D
End
If D=16
Then
DelVar DE+1->E
End
If E=16
Then
DelVar EF+1->F
End
Output(1,1,sub(Str1,F+1,1
Output(1,2,sub(Str1,E+1,1
Output(1,3,sub(Str1,D+1,1
Output(1,4,sub(Str1,C+1,1
Back to top
WhiteDwarf


Newbie


Joined: 10 Nov 2003
Posts: 19

Posted: 21 Nov 2003 02:26:31 am    Post subject:

This program doesn't seem to work for me here's my input and output


INPUT Output
1---------->00011
2----------->00012
3------------>00013
150----------->0001150
1000----------->00011000
10000------------>000110000


Last edited by Guest on 21 Nov 2003 02:28:53 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement