Computer Science Canada

Some String to Integer Issues

Author:  B-Man 31 [ 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)


Author:  andrew. [ 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.

Author:  B-Man 31 [ 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?

Author:  BigBear [ 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

Author:  B-Man 31 [ 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.

Author:  andrew. [ 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?

Author:  DemonWasp [ 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.


: