title: Count the number of times a character occurs in a text file
body: <p>I am learning C# and I want to count the number of times a character occurs in a text file. The user inputs the path to the text file and the char to search for. The program currently doesn't find any characters. What am I doing wrong? This is the code:</p>
  
  <pre><code>    public static void Main(string[] args)
      {
          string fileName;
  
          fileName = readInput("Please enter the path to the file: ");
          StreamReader fromFile = new StreamReader(fileName);
          string line;
  
          while ((line = fromFile.ReadLine()) != null)
          {
              Console.WriteLine(line);
          }
  
          int count = 0;
          char search;
          search = readSearch("Please enter the character you want to search for: ");
  
          while ((line = fromFile.ReadLine()) != null)
          {
              foreach (char letter in line)
              {
                  if (search == letter)
                  {
                      count ++;
                  }
              }
          }
  
          Console.WriteLine("{0} was found {1} time(s).", search, count);
          Console.ReadLine();
          fromFile.Close();
          Console.ReadLine();
      }
  
      private static string readInput(string questionPath)
      {
          Console.Write(questionPath);
          string input = Console.ReadLine();
          return input;
      }
  
      private static char readSearch(string questionSearch)
      {
          Console.Write(questionSearch);
          char input = Convert.ToChar(Console.Read());
          return input;
      }
  }
  </code></pre>