A89: Re: Re: ti-89 + TI-GCC vector question


[Prev][Next][Index][Thread]

A89: Re: Re: ti-89 + TI-GCC vector question




> > Ack, it's been awhile, but does anyone know how to take a int and change
> it
> > into a char pointer so i can disp it.

Printf is a very versatile function and can print more than just ints - look
around on the net.
But to just add an int, not justified of anything, try this:

char buffer[100];    // or something.
char template[] = "The int is %d right now";
int myInteger;
...
myInteger = 47;
printf(buffer,template,myInteger);
...

and buffer should contain "The int is 47 now".

(Note: you should probably use something other than printf - something that
prints into a buffer - since the TI doesn't support command-line output)

>
> I think that's the purpose of printf, but since I take a masochistic
> pleasure in writing recursive functions, try this.  Be forwarned that it's
> untested.  Niklas and others, PLEASE check my C code here - I'm still
> working on it =)
>
>
>
> // -------------------------------------------------------------------------
> --
> // Int to String routines
> // by Scott Noveck (scott@acz.org)
> // These do NOT yet handle negative numbers and are NOT portable
> // although that can be fixed easily if necessary.
> // Two versions follow below - inttostring gives only used digits
> // inttostring_fixed gives a fixed number of digits
>
> #define DIGIT_START = 0x10 // ASCII code where digits start (not portable!)
> #define STORAGE_SIZE = 5   // Width of longest possible string (int = 5)
>
> // function prototypes
> char *inttostring(int num, char *storage);
> char *inttostring_fixed(int num, int digits, char *storage);
> char *inttostring_recurse(int num, char *storage);
>
> char storage[STORAGE_SIZE+1];

This must be defined in a function, I think, but only if you're making a TI asm
program and not a DoorsOS program.

> // this is where we will store the string
> // use "storage" w/o quotes as parameter when calling funcs
>
> // inttostring
> // wrapper func that starts recursion using point to LAST byte of storage
> // this version will not give leading zeros
> // fixed width version follows below
> // returns pointer to string
> char *inttostring(int num, char *storage)
> {
>     return(inttostring_recurse(num,storage+STORAGE_SIZE));
> }
>
> // inttostring_fixed
> // wrapper func that starts recursion using point to LAST byte of storafe
Typo :)

> // this version always gives specified number of digits
> // returns pointer to string
> char *inttostring_fixed(int num, int digits, char *storage)
> {
>     inttostring_recurse(num,storage+STORAGE_SIZE);
>     return(storage+STORAGE_SIZE-digits);
> }
>
> // inttostring_recurse
> // simple recursive routine to get string
> char *inttostring_recurse(int num,char *storage)
> {
>     if (num==0) {
>         return(storage);
>     } else {
>         *storage = num % 10 + DIGIT_START;
>         return(inttostring_recurse(num/10,storage-1));
>     }
> }
> // -------------------------------------------------------------------------
> --
>
>
> //    -Scott

Looks fine - but you never can know until the program actually runs =)

 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF Quote follows:

- "Outside! What's it like?"
- "Well -- It's sort of big"
        -- (Terry Pratchett, Truckers)




References: