harish reddy

harish reddy

  • NA
  • 162
  • 33.1k

Debug error with text files

Apr 10 2018 9:14 PM
Hi.I am trying to write the below program. but error is coming . Also when i debug i am getting the error message like "could not copy....." as shown in the snapshot attached. This error comes frequently for any other programs also. why is it so?
 
//Write  simple program that counts how many times a substring(C#) occurs in a text file.
//This is our "Intro to Programming in C#" book.In it you will learn the basics of C# programming.You will find out how nice C# is.
StreamWriter writing = new StreamWriter(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt");
int count = 0;
if (File.Exists(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt"))
{
writing.Write("This is our Intro to Programming in C# book.In it you will learn the basics of C# programming.You will find out how nice C# is");
writing.Close();
StreamReader reading = new StreamReader(@"C:\Users\harish\Desktop\C Sharp\Practice\TextFiles\Occurences\Occurences.txt");
Console.WriteLine(reading.ReadLine());
string array = reading.ReadLine().Substring(0, 50);
for (int i = 0; i < array.Length; i++)
{
if (array[i] == 'C' && array[i + 1] == '#')
{
count++;
}
} Console.WriteLine(count);
reading.Close();
}

Attachment: Capture.zip

Answers (1)