Some String to Integer Issues
Author |
Message |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Thu Sep 10, 2009 5:22 pm Post subject: Some String to Integer Issues |
|
|
hey, im reading some numbers form a text file and i cant seem to convert them into string, this is what i have. any help would be awesome! Thanks
Turing: |
var levels : int
var brick_x_ 1, brick_x_ 2, brick_y_ 1, brick_y_ 2 : string (3)
var brick_colour : flexible array 1 .. 0 of string (2)
var position_brick_x_ 1 : int := 81
var position_brick_x_ 2 : int := 88
var position_brick_y_ 2 : int := 94
var position_brick_y_ 1 : int := 103
var position_brick_colour : int := 112
open : levels, "Levels.txt", seek, read
seek : levels, position_brick_x_ 1
read : levels, brick_x_ 1
seek : levels, position_brick_x_ 2
read : levels, brick_x_ 2
seek : levels, position_brick_y_ 1
read : levels, brick_y_ 1
seek : levels, position_brick_y_ 2
read : levels, brick_y_ 2
seek : levels, position_brick_colour
read : levels, brick_colour
close : levels
brick_x_ 1 := strint (brick_x_ 1)
brick_x_ 2 := strint (brick_x_ 2)
brick_y_ 1 := strint (brick_y_ 1)
brick_y_ 2 := strint (brick_y_ 2)
brick_colour := strint (brick_colour )
drawfillbox (brick_x_ 1, brick_y_ 1, brick_x_ 2, brick_y_ 2, brick_colour )
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Thu Sep 10, 2009 5:30 pm Post subject: RE:Some String to Integer Issues |
|
|
Try using strintok (brick_x_1) to see if it can be turned into an int. I think that you are reading a space or a non-integer. |
|
|
|
|
![](images/spacer.gif) |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Thu Sep 10, 2009 6:11 pm Post subject: RE:Some String to Integer Issues |
|
|
I figured it out why its not working, its because the limit i set after the string does not seem to work so it reads more.
But now i need to figure out why the read function doesnt use the limit set by the string variable. can anyone help explain this? |
|
|
|
|
![](images/spacer.gif) |
BigBear
|
Posted: Thu Sep 10, 2009 6:40 pm Post subject: RE:Some String to Integer Issues |
|
|
It doesn't matter what you put them into the test file when you open it to get you can simply get as strings |
|
|
|
|
![](images/spacer.gif) |
B-Man 31
![](http://compsci.ca/v3/uploads/user_avatars/370363944af8c60a7db3b.jpg)
|
Posted: Thu Sep 10, 2009 6:55 pm Post subject: Re: Some String to Integer Issues |
|
|
i know, ive gotten them as strings, i now need to get it to an integer, but the variable, even though it is limited string of 3 characters, still has more than 3 characters including spaces which i cant seem to explain. |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Thu Sep 10, 2009 8:16 pm Post subject: RE:Some String to Integer Issues |
|
|
Why don't you just read everything into one big string and then split it into multiple strings after? |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Thu Sep 10, 2009 11:21 pm Post subject: RE:Some String to Integer Issues |
|
|
If your string(3) types have more than 3 characters in them, then it's probably a Turing bug. Try using:
Turing: | read levels : brick_x : 3 |
to limit input to 3 bytes == 3 characters. |
|
|
|
|
![](images/spacer.gif) |
|
|