Max string (255)
Author |
Message |
Aange10
|
Posted: Thu Oct 20, 2011 7:52 pm Post subject: Max string (255) |
|
|
What is it you are trying to achieve?
I'd like to get input from a user that contains more than 255 characters.
What is the problem you are having?
Turings maximum string size is 255 characters.
Describe what you have tried to solve this problem
Brainstorming. But the biggest thing I run into is, there's no way to check what the client is inputting before they are through (It's not yet input!).
Is this possible to do? If so, what tools would I go about accomplishing this with?
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
N/A
Please specify what version of Turing you are using
4.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Thu Oct 20, 2011 7:55 pm Post subject: RE:Max string (255) |
|
|
Why would you want input that long in the first place? Try breaking it into multiple lines based on a logical event in the input. Something like, perhaps, a space. |
|
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 8:05 pm Post subject: Re: RE:Max string (255) |
|
|
Insectoid @ 20/10/2011, 6:55 pm wrote: Why would you want input that long in the first place?
Because I need to input questions that contain more than 255 characters.
Insectoid @ 20/10/2011, 6:55 pm wrote: Try breaking it into multiple lines based on a logical event in the input.
If the client needed to type a question that was 300 characters long, how would I break up his imput before i recieved it? How do i even make him know he's reached the limit?
Insectoid @ 20/10/2011, 6:55 pm wrote: Something like, perhaps, a space.
What's that suppose to mean |
|
|
|
|
|
2goto1
|
Posted: Thu Oct 20, 2011 8:11 pm Post subject: RE:Max string (255) |
|
|
You may have to use getch and read characters in one by one. |
|
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 8:17 pm Post subject: RE:Max string (255) |
|
|
So I don't have a way for them to just type in a response longer than 255? And if I do the getch, wont it require them to type like "A [enter] (Space) [enter] B [enter] . . ."?
Also, I should have shown this... I want it for this program.
Turing: |
var T_F1, T_F2, T_F3, T_F4, T_F5 : string
var M_C1, M_C2, M_C3, M_C4, M_C5 : string
var M_C_A1, M_C_A2, M_C_A3, M_C_A4, M_C_A5 : string
var M_C_B1, M_C_B2, M_C_B3, M_C_B4, M_C_B5 : string
var M_C_C1, M_C_C2, M_C_C3, M_C_C4, M_C_C5 : string
var M_C_D1, M_C_D2, M_C_D3, M_C_D4, M_C_D5 : string
var F_B1, F_B2, F_B3, F_B4, F_B5 : string
var name,dates,ws : string
put "Name first & last?"
get name : *
put "Date?"
get dates : *
put "Ws number (i.e 2-2)"
get ws : *
put "What is T/F question 1?"
get T_F1 : *
put "What is T/F question 2?"
get T_F2 : *
put "What is T/F question 3?"
get T_F3 : *
put "What is T/F question 4?"
get T_F4 : *
put "What is T/F question 5?"
get T_F5 : *
cls
put "What is Multiple Choice question 1?"
get M_C1 : *
put "Answer A: "
get M_C_A1 : *
put "Answer B: "
get M_C_B1 : *
put "Answer C: "
get M_C_C1 : *
put "Answer D: "
get M_C_D1 : *
cls
put "What is Multiple Choice question 2?"
get M_C2 : *
put "Answer A: "
get M_C_A2 : *
put "Answer B: "
get M_C_B2 : *
put "Answer C: "
get M_C_C2 : *
put "Answer D: "
get M_C_D2 : *
cls
put "What is Multiple Choice question 3?"
get M_C3 : *
put "Answer A: "
get M_C_A3 : *
put "Answer B: "
get M_C_B3 : *
put "Answer C: "
get M_C_C3 : *
put "Answer D: "
get M_C_D3 : *
cls
put "What is Multiple Choice question 4?"
get M_C4 : *
put "Answer A: "
get M_C_A4 : *
put "Answer B: "
get M_C_B4 : *
put "Answer C: "
get M_C_C4 : *
put "Answer D: "
get M_C_D4 : *
cls
put "What is Multiple Choice question 5?"
get M_C5 : *
put "Answer A: "
get M_C_A5 : *
put "Answer B: "
get M_C_B5 : *
put "Answer C: "
get M_C_C5 : *
put "Answer D: "
get M_C_D5 : *
cls
put "What is Fill In The Blank question 1?"
get F_B1 : *
put "What is Fill In The Blank question 2?"
get F_B2 : *
put "What is Fill In The Blank question 3?"
get F_B3 : *
put "What is Fill In The Blank question 4?"
get F_B4 : *
put "What is Fill In The Blank question 5?"
get F_B5 : *
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
View.Set ("offscreenonly,text")
put name
put "Mrs. Barnes"
put "2nd Hour Computer Literacy"
put "Worksheet ",ws
put dates
put " "
put " "
put " TRUE/FALSE " % 4 tabs [text] 4 tabs
put " T F 1. ", T_F1 % Space, tab, tab, 1.
put " T F 2. ", T_F2 % Space, tab, tab, 2.
put " T F 3. ", T_F3 % Space, tab, tab, 3.
put " T F 4. ", T_F4 % Space, tab, tab, 4.
put " T F 5. ", T_F5 % Space, tab, tab, 5.
put " " %same as /n
put " " %same as /n
put " " %same as /n
put " MULTIPLE CHOICE " % 4 tabs [text] 4 tabs
put " 1. ", M_C1 %Tab 1.
put " A. ", M_C_A1, " c. ", M_C_C1 %2 tab, 4 tab
put " B. ", M_C_B1, " D. ", M_C_D1 %2 tab, 4 tab
put " 2. ", M_C2 %Tab 1.
put " A. ", M_C_A2, " c. ", M_C_C2 %2 tab, 4 tab
put " B. ", M_C_B2, " D. ", M_C_D2 %2 tab, 4 tab
put " 3. ", M_C3 %Tab 1.
put " A. ", M_C_A3, " c. ", M_C_C3 %2 tab, 4 tab
put " B. ", M_C_B3, " D. ", M_C_D3 %2 tab, 4 tab
put " 4. ", M_C4 %Tab 1.
put " A. ", M_C_A4, " c. ", M_C_C4 %2 tab, 4 tab
put " B. ", M_C_B4, " D. ", M_C_D4 %2 tab, 4 tab
put " 5. ", M_C5 %Tab 1.
put " A. ", M_C_A5, " c. ", M_C_C5 %2 tab, 4 tab
put " B. ", M_C_B5, " D. ", M_C_D5 %2 tab, 4 tab
put " " % same as /n
put " " % same as /n
put " " % same as /n
put " FILL IN THE BLANK " % 4 tabs [text] 4 tabs
put " 1. ", F_B1 %Tab 1.
put " 2. ", F_B2 %Tab 1.
put " 3. ", F_B3 %Tab 1.
put " 4. ", F_B4 %Tab 1.
put " 5. ", F_B5 %Tab 1.
View.Update
|
|
|
|
|
|
|
Insectoid
|
Posted: Thu Oct 20, 2011 8:25 pm Post subject: RE:Max string (255) |
|
|
You'll need getch() I think. get should never be used to input a large string.
Fortunately, way back in the day (three or four years ago) I wrote a Blackjack program that uses a custom text input mode. I won't explain it (I haven't looked at the code in years) but I'm sure you can figure it out.
It's in this thread.
I'd explain in detail if I had time, however I don't have time so I can't explain in detail. |
|
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 9:24 pm Post subject: RE:Max string (255) |
|
|
Figured it out! ... For future reference:
Turing: |
var line : flexible array 1 .. 1 of string (1) % Input
var line_after : flexible array 1 .. 1 of string % Medium/Output
var misc : int
%Gets input
for i : 1 .. maxint
getch(line (i ))
put line (i ) ..
if line (i ) = chr(10) then
exit
end if
new line, upper(line ) + 1
end for
%Sets Medium/Output upper (line_after)
if round(upper(line ) div 255) <= 0 then
new line_after, 1
for i : 1 .. upper(line_after ) % Declare
line_after (i ) := ""
end for
else
new line_after, round(upper(line ) div 255) + 1
for i : 1 .. upper(line_after ) % Declare
line_after (i ) := ""
end for
end if
% Define Medium/Output (line_after)
if upper(line ) > 255 then
for i : 1 .. upper(line )
misc := round((i div 255))
if misc <= 0 then
misc := 1
else
misc + = 1
end if
line_after (misc ) + = line (i )
end for
else
for i : 1 .. upper(line )
line_after (1) + = line (i )
end for
end if
% Output
cls
delay(2000) % So you can notice!
for i : 1 .. upper(line_after )
put line_after (i ) ..
end for
|
Thanks insect, 2go! |
|
|
|
|
|
mirhagk
|
Posted: Thu Oct 20, 2011 9:42 pm Post subject: RE:Max string (255) |
|
|
HUGE piece of advice, look into arrays. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Thu Oct 20, 2011 9:45 pm Post subject: RE:Max string (255) |
|
|
code: |
%Gets input
for i : 1 .. maxint
getch(line(i))
put line(i) ..
if line(i) = chr(10) then
exit
end if
new line, upper(line) + 1
end for
|
reallocating the entire array at every new character is expensive. The typical approach is to double the size of the array when needing extra space. This gives you O(logn) resizes, rather than O(n). There might be some unused memory allocated, but that is guaranteed to be less than half the string. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Beastinonyou
|
Posted: Thu Oct 20, 2011 10:12 pm Post subject: Re: RE:Max string (255) |
|
|
Aange10 @ Thu Oct 20, 2011 8:17 pm wrote: So I don't have a way for them to just type in a response longer than 255? And if I do the getch, wont it require them to type like "A [enter] (Space) [enter] B [enter] . . ."?
Also, I should have shown this... I want it for this program.
My God, Did you write that long, unnecessary, inefficient program that looks like you Stuttered put's and get's all the way through it?
I highly advise you use Arrays and For repetitive structures. it will Severely cut down the lines. |
|
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 10:43 pm Post subject: RE:Max string (255) |
|
|
It was written when i first started. Forgive me for not knowing arrays then :p |
|
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 10:46 pm Post subject: Re: RE:Max string (255) |
|
|
Tony @ 20/10/2011, 8:45 pm wrote: code: |
%Gets input
for i : 1 .. maxint
getch(line(i))
put line(i) ..
if line(i) = chr(10) then
exit
end if
new line, upper(line) + 1
end for
|
reallocating the entire array at every new character is expensive. The typical approach is to double the size of the array when needing extra space. This gives you O(logn) resizes, rather than O(n). There might be some unused memory allocated, but that is guaranteed to be less than half the string.
Do you mean not use a dynamic array? How would I know much to double my array? |
|
|
|
|
|
Tony
|
Posted: Thu Oct 20, 2011 10:52 pm Post subject: Re: RE:Max string (255) |
|
|
Still a flexible array, but increase the size less often.
Aange10 @ Thu Oct 20, 2011 10:46 pm wrote: How would I know much to double my array?
You accidentally a word. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Aange10
|
Posted: Thu Oct 20, 2011 11:43 pm Post subject: RE:Max string (255) |
|
|
Turing: |
var line : flexible array 1 .. 1 of string (1) % Input
var line_after : flexible array 1 .. 1 of string % Medium/Output
var counter : int := 0 % Counter
var misc : int
%Gets input
for i : 1 .. maxint
getch (line (i ))
put line (i ) ..
counter + = 1
if line (i ) = chr (10) then
exit
end if
%Double Array size
if i + 1 >= upper (line ) then
new line, upper (line ) * 2
end if
end for
%Sets Medium/Output upper (line_after)
if round (upper (line ) div 255) <= 0 then
new line_after, 1
for i : 1 .. upper (line_after ) % Declare
line_after (i ) := ""
end for
else
new line_after, round (upper (line ) div 255) + 1
for i : 1 .. upper (line_after ) % Declare
line_after (i ) := ""
end for
end if
% Define Medium/Output (line_after)
if upper (line ) > 255 then
for i : 1 .. counter
misc := round ((i div 255))
if misc <= 0 then
misc := 1
else
misc + = 1
end if
line_after (misc ) + = line (i )
end for
else
for i : 1 .. counter
line_after (1) + = line (i )
end for
end if
% Output
cls
delay(2000)
for i : 1 .. upper (line_after )
put line_after (i ) ..
end for
|
More efficient? I made it double the array each time it was 1 element before running out, as to not have to reallocate it as often. I made a counter variable to count how many characters I've set out. |
|
|
|
|
|
|
|