Computer Science Canada questions about string(1) converting |
Author: | yawam [ 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 :\ |
Author: | copthesaint [ Mon Oct 11, 2010 8:59 pm ] |
Post subject: | RE:questions about string(1) converting |
Gee MUMBERS are pretty hard arnt they? |
Author: | Zren [ 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(). |
Author: | yawam [ 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.. |
Author: | Zren [ 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)?
|
Author: | yawam [ 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>< |
Author: | Zren [ 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. |
Author: | yawam [ 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? |
Author: | Zren [ 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. |
Author: | yawam [ 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 |
Author: | copthesaint [ 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.
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. |