Computer Science Canada Max string (255) |
Author: | Aange10 [ 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 |
Author: | Insectoid [ 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. |
Author: | Aange10 [ 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 |
Author: | 2goto1 [ 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. |
Author: | Aange10 [ 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.
|
Author: | Insectoid [ 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. |
Author: | Aange10 [ Thu Oct 20, 2011 9:24 pm ] | ||
Post subject: | RE:Max string (255) | ||
Figured it out! ... For future reference:
Thanks insect, 2go! |
Author: | mirhagk [ Thu Oct 20, 2011 9:42 pm ] |
Post subject: | RE:Max string (255) |
HUGE piece of advice, look into arrays. |
Author: | Tony [ Thu Oct 20, 2011 9:45 pm ] | ||
Post subject: | RE:Max string (255) | ||
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. |
Author: | Beastinonyou [ 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. |
Author: | Aange10 [ 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 |
Author: | Aange10 [ Thu Oct 20, 2011 10:46 pm ] | ||
Post subject: | Re: RE:Max string (255) | ||
Tony @ 20/10/2011, 8:45 pm wrote:
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? |
Author: | Tony [ 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. |
Author: | Aange10 [ Thu Oct 20, 2011 11:43 pm ] | ||
Post subject: | RE:Max string (255) | ||
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. |