How can I increase the char capacity?

Pages: 12
@Smac89:
How am I looking to read multi-line strings?
I just want to store a single-line input from user into array [10,000], then I convert his input and store each character of the converted into arraybin [100,000] which I will output at the end.
Thanks in advance!
If you are actually reading in a 10,000 character string, line 9 is incorrect. Actually reading the documentation for the functions you are using is good.

Line 9 should be std::cin.getline(array, size+1, '\n');. Notice the +1.

In the loop on line 34 you access outside the bounds of your arrays, resulting in undefined behavior. How did I determine this? I converted your arrays to vectors, reduced the size of the expected input to an amount that was easier to work with and let the vector tell me when you accessed out of bounds.

You could've done the same thing by placing a few conditional breakpoints in a debugger.
Last edited on
What operating system are you using, and how are you giving the input to the program?

On my system, I can only type up to 4095 characters of input into the console screen, but if I give it the input from a file (via myprog < file_containing_10000_chars.txt), it will read all 10000 characters.

When you say that the program doesn't output anything if you give it too many characters, do you mean that the program is hanging/crashing or that the program terminates normally with no output at all?

With a few small modifications (that I mentioned in my previous post), when I give it input from a file containing 10000 'a's, it reads all 10000 characters and then proceeds to spit out
11000011100001110000111000011...

I cut off the program before it finished, so I don't know if it would have crashed at some point or not, but in any case, I got at least some output.
@cire:
I think the problem is in the input method, not in the code.
Could you please tell me why this could happen?
Thanks in advance!

@long double main:
How can I have my input from a text instead of keyboard, and also the output to a file instead of showing it on the screen?
Thanks in advance!
Thanks a lot!
The problem is in the input method not in the char capacity!!
When the input method is the keyboard and the output is the screen, the program doesn't perform well. But, when the input and output method is a .txt file the program performs well.
I really don't know what actually causes that, But if any knows please tell us :)
Topic archived. No new replies allowed.
Pages: 12