using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace WordCount { struct Wordcount { public string word; public int count; } class Program { static void Main(string[] args) { Wordcount[] wordCount = new Wordcount[2000]; string inputLine; string inputFilePath; FileStream inputFileStream; StreamReader streamReader; Console.WriteLine(@"Enter input file path (EX: I:\mccleary\Outbox\cs313 shared files\Jesus Prayer.txt): "); inputFilePath = Console.ReadLine(); Console.WriteLine("\n\n"); try { inputFileStream = new FileStream(inputFilePath, FileMode.Open); streamReader = new StreamReader(inputFileStream); } catch (IOException e) { Console.WriteLine("An IO exception has been thrown while opening the input file!"); Console.WriteLine(e.ToString()); Console.Write("\n\n Hit any key to exit program"); Console.ReadKey(); return; } inputLine = streamReader.ReadLine(); while (inputLine != null) { inputLine = inputLine.ToLower().Trim(); for (int i = 0; i < inputLine.Length; i++) { char currentChar = inputLine[i]; if (currentChar != ' ' && (!Char.IsLetter(currentChar))) { inputLine = inputLine.Replace(currentChar, ' '); } } string[] words = inputLine.Split(' '); foreach (string inputWord in words) { if(inputWord.Length > 0) { for (int i = 0; i < wordCount.Length; i++ ) { if (wordCount[i].word == null) { wordCount[i].count++; wordCount[i].word = inputWord; i = wordCount.Length; } else if (wordCount[i].word.Equals(inputWord)) { wordCount[i].count++; i = wordCount.Length; } else { } } } } inputLine = streamReader.ReadLine(); } streamReader.Close(); for (int i = 0; i < wordCount.Length; i++) { if (wordCount[i].word != null) { Console.WriteLine(wordCount[i].word + " " + wordCount[i].count); } else { i = wordCount.Length; } } Console.Write("\n\n Hit any key to exit program"); Console.ReadKey(); } } }