
-----------------------------------
Mephi
Sun Apr 27, 2003 2:50 pm

Max string size
-----------------------------------
how do you make it so that if a person puts in more than 256 characters or whatever the limit is it doesn't crash? can you make it so theres no limit?

-----------------------------------
Asok
Sun Apr 27, 2003 2:52 pm


-----------------------------------
var str : string
put "enter the string"
get str : 6
put str

this for example will only get the first 6 characters in the string

-----------------------------------
nate
Sun Apr 27, 2003 2:56 pm

this is how i do it
-----------------------------------
var text : string (20)

get text : 20

put text

This limits both the variable and the text you can enter. Right now it is 20 but you can change it to the 250 limit

-Nate

-----------------------------------
Mephi
Sun Apr 27, 2003 3:01 pm

Umm...
-----------------------------------
hey nate:P  (to both) they dont work.....if you put in a number larger than 255 its an error

-----------------------------------
Asok
Sun Apr 27, 2003 3:09 pm


-----------------------------------
mephi, are you trying to exceed the 255 cap or make it so that the user doesn't enter into the 255 cap?

-----------------------------------
Mephi
Sun Apr 27, 2003 3:10 pm

both
-----------------------------------
well exceed mainly, but i guess just limiting is ok too....thx....as long as it duznt crash (my comp teachers really stingy, he keeps tryin to crash our programs ne way possible)

-----------------------------------
Mephi
Sun Apr 27, 2003 3:27 pm

erm..
-----------------------------------
var x :string
get x : 8
put x, "!"


how come if its less than 8 the ! goes on a different line? or is this just me?

-----------------------------------
Tony
Sun Apr 27, 2003 3:28 pm


-----------------------------------
I belive this issue was already addressed by the use of getch() in a loop


var c:string(1) %for getch
var text:string := "" %store text here
var counter:int := 0 %counter

put "enter your string, 255 max"

loop
getch(c)
if c=chr(10) then %if enter is pressed
exit
end if
text := text + c
counter += 1

if counter =255 then %your string is already 255 long
put "I said 255 characters max"
exit
end if

end loop

put "your string is : ", text


-----------------------------------
Mephi
Sun Apr 27, 2003 3:38 pm

nvm
-----------------------------------
nvm i found an easier way:
var x : string
get x
if length (x) > 8 then
    x := x (1 .. 8)
end if
put x, "!"

just takes first 8 characters

-----------------------------------
Tony
Sun Apr 27, 2003 3:42 pm


-----------------------------------
well you can still type in 300 characters and your program will crash. Using getch will read input 1 key at a time, safeguarding your string variable

-----------------------------------
jamez
Thu May 01, 2003 9:14 am

Re: nvm
-----------------------------------
nvm i found an easier way:
var x : string
get x
if length (x) > 8 then
    x := x (1 .. 8)
end if
put x, "!"

just takes first 8 characters


have 'get x' allows the user to input 1000s of characters
