Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 questions about string(1) converting
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yawam




PostPosted: Mon Oct 11, 2010 8:08 pm   Post subject: questions about string(1) converting

hi guys
im new to turing, so today im just trying to play around with the codes

and i found a problem (which i dont know what's goin on and how to solve it :f)


here's the codes

var number : string(1)
get mumber
put number

it does work when you run it
[b]but once you enter a negative number, it wont run properly anymore, it wont return the input[/b]
it turns out to be "input string is too large for the string varibale"
so, how can i get a negative number work in string? or how can i convert a string type negative number to interger type?

btw..this is what i got when i try to convert a string type negative to interger...\\\
"string passed to strrint is not correct format"

please help out here :\
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Mon Oct 11, 2010 8:59 pm   Post subject: RE:questions about string(1) converting

Gee MUMBERS are pretty hard arnt they?
Zren




PostPosted: Mon Oct 11, 2010 9:12 pm   Post subject: RE:questions about string(1) converting

xD Mumbers.

Anyways
get will put the entire input string into the variable you give. The string number has room for only one character. Since negative numbers will essentially need two chracteracters "-" and "7". This breaks numbers.

You don't need to place an upper limit on numbers. You only need to do this when you use getch().
yawam




PostPosted: Mon Oct 11, 2010 9:16 pm   Post subject: Re: RE:questions about string(1) converting

copthesaint @ Mon Oct 11, 2010 8:59 pm wrote:
Gee MUMBERS are pretty hard arnt they?


lol..my bad..
Zren




PostPosted: Mon Oct 11, 2010 9:20 pm   Post subject: Re: questions about string(1) converting

Uhg >.< I like to post-edit too much. Doesn't work when people answer like the lightning king.

Removing the upper limit should work for numbers with <1024 characters. . . I think your good.

Not sure whats'up with your negative numbers. They seem to work. Anyways, you might want to check your string input before converting with strintok(String)?
Turing:

var line:string
var num:int

get line
if strintok(line) then
    num := strint(line)
else
    num := 0
end if
put num
yawam




PostPosted: Mon Oct 11, 2010 9:24 pm   Post subject: RE:questions about string(1) converting

@Zren thank you for yor responding xd

but what if i do need to use it with getch()

how can it work? im confused><
Zren




PostPosted: Mon Oct 11, 2010 9:30 pm   Post subject: RE:questions about string(1) converting

Why do you need to use it with getch()? getch() is more so used for creating your own user input model (or a simple, press any key to continue method). I can further explain getch() and get if your fully interested.

You can still use get to get strings of 1 character, 2 characters, 3... etc. The whole point of get is to get a string of undetermined size. It itself does the whole looping of getch and printing it to the screen to give the user feedback to what he's entering into the field.
yawam




PostPosted: Mon Oct 11, 2010 9:35 pm   Post subject: RE:questions about string(1) converting

yeah..i know

just try to figure out how it works lol

is there anyway that i can ..ehm.for example

i enter -445 as STRING(1)type
how can i convert it to INTERGER?
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Mon Oct 11, 2010 9:40 pm   Post subject: RE:questions about string(1) converting

String(1) cant hold 4 characters. "-", "4", "4", "5". String(1) only has room for 1 character.
String(16) can hold 16 characters.
String can hold the default maximum characters (which is 1024 I think).

Read the example above for code referring to String -> Integer.
yawam




PostPosted: Mon Oct 11, 2010 9:48 pm   Post subject: RE:questions about string(1) converting

i tried it befor didnt work out so well
i guees it's some other parts of the program that doesnt work or something

thank you anyway.XD
copthesaint




PostPosted: Mon Oct 11, 2010 10:36 pm   Post subject: Re: questions about string(1) converting

Simplest programing on the face of the planet, GOD! I wish java was this easy.
Turing:
View.Set ("Graphics,offscreenonly,nobuttonbar")
var s : string := ""
loop
    if hasch then
        s := s + getchar
        Input.Flush
        delay (100)
    end if
    put s
    View.Update
    cls
end loop


The only difference between getch () and getchar. getch in turing is a "procedure" and getchar is "function", because in turing, procedures only take values, while functions take and give values.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: