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

Username:   Password: 
 RegisterRegister   
 Max string size
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mephi




PostPosted: Sun Apr 27, 2003 2:50 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Sun Apr 27, 2003 2:52 pm   Post subject: (No subject)

code:
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




PostPosted: Sun Apr 27, 2003 2:56 pm   Post subject: 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




PostPosted: Sun Apr 27, 2003 3:01 pm   Post subject: Umm...

hey nate:P (to both) they dont work.....if you put in a number larger than 255 its an error
Asok




PostPosted: Sun Apr 27, 2003 3:09 pm   Post subject: (No subject)

mephi, are you trying to exceed the 255 cap or make it so that the user doesn't enter into the 255 cap?
Mephi




PostPosted: Sun Apr 27, 2003 3:10 pm   Post subject: 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




PostPosted: Sun Apr 27, 2003 3:27 pm   Post subject: erm..

code:
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




PostPosted: Sun Apr 27, 2003 3:28 pm   Post subject: (No subject)

I belive this issue was already addressed by the use of getch() in a loop

code:

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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mephi




PostPosted: Sun Apr 27, 2003 3:38 pm   Post subject: nvm

nvm i found an easier way:
code:
var x : string
get x
if length (x) > 8 then
    x := x (1 .. 8)
end if
put x, "!"

just takes first 8 characters
Tony




PostPosted: Sun Apr 27, 2003 3:42 pm   Post subject: (No subject)

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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
jamez




PostPosted: Thu May 01, 2003 9:14 am   Post subject: Re: nvm

Mephi wrote:
nvm i found an easier way:
code:
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
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  [ 11 Posts ]
Jump to:   


Style:  
Search: