forked from KrisLamontagne/CodeJamTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (76 loc) · 2.6 KB
/
Program.cs
File metadata and controls
89 lines (76 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace reverseWords
{
public class Program
{
static void Main(string[] args)
{
string inputFile;
string outputFile;
string processedData;
inputFile = GetFilePath("Enter Input File: ");
outputFile = GetFilePath("Enter Output File: ");
processedData = ProcessFile(inputFile);
WriteToFile(outputFile, processedData);
}
/// <summary>
/// Prompts the user to enter a path to a file
/// </summary>
///
/// <param name="message">The message that is displayed to the user</param>
///
/// <returns>A string containing the path to a file</returns>
private static string GetFilePath(string message)
{
string filePath;
do
{
Console.Write(message);
filePath = Console.ReadLine();
} while (filePath == null || filePath.Trim().Length == 0);
return filePath;
}
/// <summary>
/// Processes the input file
/// </summary>
///
/// <param name="input">The input file that will be processed</param>
///
/// <returns>A string containing the output from processing the file</returns>
private static string ProcessFile(string input)
{
string currentLine;
StringBuilder stringBuilder = new StringBuilder();
using( StreamReader reader = new StreamReader(input) )
{
currentLine = reader.ReadLine();
//TODO: Possibly use WHILE instead of IF?
if( currentLine != null )
{
//TODO: Write logic to process the input file
}
reader.Close();
}
return stringBuilder.ToString();
}
/// <summary>
/// Writes data to a file
/// </summary>
///
/// <param name="outputFile">The output file to write to</param>
/// <param name="words">The data that will be written to the file</param>
private static void WriteToFile(string outputFile, string words)
{
using(StreamWriter writer = new StreamWriter(outputFile))
{
writer.Write(words);
writer.Close();
}
}
}
}