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

Username:   Password: 
 RegisterRegister   
 What is strintok
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xSonu




PostPosted: Wed Jan 20, 2010 10:01 pm   Post subject: What is strintok

I`m a bit confused. I know strintok is a error trap but what does it really mean.

Yea yea, i know you people are probably saying go check the reference manual or its on the site.

But the definitions on the site and manual, i dont get them

i mean converting string to integer Question

its not getting to me, could someone explain it in a more simpler way.
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Wed Jan 20, 2010 10:27 pm   Post subject: RE:What is strintok

Turing:

var str:="99"
var x:int
if strintok(str) then
    x := strint(str)


If string can convert to an integer then,
X is the integer value of Str.

Basically it checks the string if it's compatible as an Integer, and returns true or false. If it's false, then you skip the conversion and immenent failure.
TerranceN




PostPosted: Wed Jan 20, 2010 10:31 pm   Post subject: Re: What is strintok

strint changes a string to an integer, but if the string has something other than letters, your program will crash. This is where strintok becomes useful.

stringok checks if you can convert a string to an integer, so:

Turing:
strintok("5") % returns true


but

Turing:
strintok("wsecuy") % returns false


so if you use this in an if statement with strint, you can prevent the error, and even say what to do if there would have been an error

Turing:
var num : int := 0
var str : string := "5"

if strintok(str) then
    num := strint(str)
else
    % handle error
end if

put num


Hope that helps
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  [ 3 Posts ]
Jump to:   


Style:  
Search: