When reading a file and subsequent transformations, the original numbers from the file in the string format are shortened. The file itself has 2 numbers with a length of more than 50 characters.

The task relates to the topic "algorithms of long arithmetic". I tried to write data to an array and output it, and it turns out the same shortened result.

Tell me, please, what could be the problem?

Code Listing:

class Program { static void Main(string[] args) { List<string> number1 = (File.ReadAllLines("G:\\subtraction.txt")).ToList(); File.WriteAllLines("G:\\output_substraction.txt", number1); foreach (var s in number1) { Console.WriteLine(s); } Console.ReadLine(); } } 
  • Have you tried debugging? Well, there put a breakpoint on the record line, and see how many elements were read in number1 ? To begin to identify the problem area. - Bulson
  • @Bulson foreach cycle passes 2 times as it should be, did not notice anything remarkable. The File.ReadAllLines method takes the lines from the file, so I think everything is correct. - Ramil
  • one
    More information is needed: show what was at the entrance, what was at the output, how they are shortened, maybe they are glued together in one number, because do not contain the character of transition to a new line between themselves? - Bulson
  • @Bulson Problem solved (albeit partially), but still it would be interesting to know why the first version of the code did not work. As for the initial information, 2 numbers are in the txt file on the first and second lines, respectively, separated by a newline character ('\ n'). - Ramil

1 answer 1

The problem is completely solved. Modified code:

 static void Main(string[] args) { StreamReader sr = new System.IO.StreamReader("G:\\subtraction.txt"); string str; var numbers = new List<string>(); while ((str = sr.ReadLine()) != null) { numbers.Add(str); } foreach (var k in numbers) { Console.WriteLine(k); } Console.ReadLine(); } 

txt file