using System; using System.IO; namespace TextImprecision { class Program { static void Main(string[] args) { Console.WriteLine("Enter the first file path: "); string p1 = Console.ReadLine(); Console.WriteLine("Enter the second file path: "); string p2 = Console.ReadLine(); TextWriter output = File.CreateText("Imprecision.txt"); TextReader tr1 = File.OpenText(p1.Trim('\"')); TextReader tr2 = File.OpenText(p2.Trim('\"')); output.WriteLine("Differences between {0} and {1}:", p1, p2); bool exit = false; #nullable enable while (!exit) { string? nl1 = tr1.ReadLine(); string? nl2 = tr2.ReadLine(); if (nl1 == null || nl2 == null) { exit = true; } else { // Clear leading/trailing whitespace nl1 = nl1.Trim(); nl2 = nl2.Trim(); // Get the numbers by themselves string strDbl1 = nl1[..nl1.IndexOf(' ')]; string strDbl2 = nl1[nl1.IndexOf(' ')..].Trim(); string strDbl3 = nl2[..nl2.IndexOf(' ')]; string strDbl4 = nl2[nl2.IndexOf(' ')..].Trim(); // int nonMatchIndex1 = -1; int decimalPos1 = -1; int nonMatchIndex2 = -1; int decimalPos2 = -1; for (int i = 0; i < Math.Max(strDbl1.Length, strDbl3.Length); i++) { if (strDbl1[i < strDbl1.Length ? i : strDbl1.Length - 1] == '.' || strDbl3[i < strDbl3.Length ? i : strDbl3.Length - 1] == '.') { decimalPos1 = i; } if (strDbl1[i < strDbl1.Length ? i : strDbl1.Length-1] != strDbl3[i < strDbl3.Length ? i : strDbl3.Length - 1]) { nonMatchIndex1 = i; break; } } for (int i = 0; i < Math.Max(strDbl2.Length, strDbl4.Length); i++) { if (strDbl2[i < strDbl2.Length ? i : strDbl2.Length - 1] == '.' || strDbl4[i < strDbl4.Length ? i : strDbl4.Length - 1] == '.') { decimalPos2 = i; } if (strDbl2[i < strDbl2.Length ? i : strDbl2.Length - 1] != strDbl4[i < strDbl4.Length ? i : strDbl4.Length - 1]) { nonMatchIndex2 = i; break; } } if (nonMatchIndex1 > -1) { if (decimalPos1 > -1) { output.Write("{0} dp", nonMatchIndex1 - decimalPos1, strDbl1.Length < strDbl3.Length ? strDbl1.Length : strDbl3.Length); } else { output.Write("{0} sf", nonMatchIndex1); } } else { output.Write("match"); } output.Write("\t"); if (nonMatchIndex2 > -1) { if (decimalPos2 > -1) { output.Write("{0} dp", nonMatchIndex2 - decimalPos2, strDbl2.Length < strDbl4.Length ? strDbl2.Length : strDbl4.Length); } else { output.Write("{0} sf", nonMatchIndex2); } } else { output.Write("match"); } output.WriteLine("\t({0:#.000000}\t{1:#.000000})", Math.Abs(Convert.ToDouble(strDbl1)-Convert.ToDouble(strDbl3)), Math.Abs(Convert.ToDouble(strDbl2) - Convert.ToDouble(strDbl4))); } } output.Close(); } } }