0

I have c# console application. I want to read user input separated by space but my console application stops reading space separated input after count 87. what is the reason. for example below is the count 87.I want to read 90 inputs separated by space. and it stops reading inputs after count 87.

1 1 1 1 1 1 1 12 22 22 22 22 22 222 222 222 222 222 222 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 31 22 22 22 22 22 22 22 22 22 2 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 2 2 2 2 22 22 22 22 22.

My console application code is;

string[] temp = Console.ReadLine().Split(' ');
int[] height = Array.ConvertAll(height_temp, Int32.Parse);

above as accoding to above input 90. height should be 90 but it gives me height 87. infact it stops reading inputs after count 87.

Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
raja
  • 83
  • 2
  • 3
  • 16
  • I count 87 integer values in that input string. (After removing the final point to avoid an exception in Int32.Parse) – Steve Jan 25 '18 at 06:29
  • You do not convert the right variable. you read it to "temp" and then you converter "height_temp"? – Stephu Jan 25 '18 at 06:30
  • my point/ question is why console application stops reading input after some limit? their is no issue with height. I just give above code for explanation. – raja Jan 25 '18 at 06:32
  • if you just run your console application and start typing any value. if will stops getting values at some point. why it is like tha. – raja Jan 25 '18 at 06:33
  • your avswer is here : https://stackoverflow.com/questions/5557889/console-readline-max-length – Hasan Fathi Jan 25 '18 at 06:35
  • ok thanks to all of your for quick response – raja Jan 25 '18 at 06:38
  • @raja Your code is working fine, there is no problem with your code. [See here working](https://ideone.com/jRQ5D0). _Note_: In line `int[] height = Array.ConvertAll(height_temp, Int32.Parse)`, `height_temp` is changed to `temp` as `height_temp` is not defined in this scope. – cse Jan 25 '18 at 06:43

1 Answers1

0

There is a character limit for Console.ReadLine(). It should be 256 characters if I am not mistaken. So, you can increase the limit like that;

Console.SetIn(new StreamReader(Console.OpenStandardInput(),
    Console.InputEncoding,
    false,
    bufferSize: 1024));
string[] temp = Console.ReadLine().Split(' ');
int[] height = Array.ConvertAll(temp, Int32.Parse);
lucky
  • 12,734
  • 4
  • 24
  • 46