aboutsummaryrefslogtreecommitdiffstats
path: root/src/Program
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-10-11 11:43:36 -0500
committerToby Vincent <tobyv13@gmail.com>2021-10-11 11:43:36 -0500
commit067ceeaee485d2099f30085c964296cb0f4144ac (patch)
tree727298498f88645978b1b74602da5ff1a94d2da2 /src/Program
parentf0df0ba7ed89ed347a11ec5257ac22042775e164 (diff)
fixed filepath io and finalized for release
Diffstat (limited to 'src/Program')
-rw-r--r--src/Program/Program.cs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Program/Program.cs b/src/Program/Program.cs
index f4c83d1..9985c10 100644
--- a/src/Program/Program.cs
+++ b/src/Program/Program.cs
@@ -9,13 +9,14 @@ namespace ClosestPair
{
public static void Main(string[] args)
{
- FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : new FileInfo("points1.txt");
+ FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : ReadFileName();
- if (!inputFile.Exists) {
+ if (!inputFile.Exists)
+ {
Console.WriteLine($"Failed to open {inputFile}: File does not exist.");
return;
}
-
+
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Point[] points = PointFile.ReadFile(inputFile.FullName);
@@ -28,6 +29,28 @@ namespace ClosestPair
Console.WriteLine($"Closest Points: {closestPair.ToString("F3")}");
Console.WriteLine($"Runtime: {ts.ToString("mm\\:ss\\.ff")}");
}
+ public static FileInfo ReadFileName()
+ {
+ FileInfo file = new FileInfo(" ");
+ string? filePath;
+
+ while (true)
+ {
+ Console.Write("Enter a path to a points file: ");
+ filePath = Console.ReadLine();
+
+ if (String.IsNullOrEmpty(filePath))
+ Console.WriteLine("File path cannot be empty!");
+ else if (!System.IO.File.Exists(filePath))
+ Console.WriteLine($"{filePath} does not exist.");
+ else
+ break;
+ }
+
+ file = new FileInfo(filePath);
+
+ return file;
+ }
}
} \ No newline at end of file