Create a C# program with the following functionalities: Input file (James bond,
ID: 639988 • Letter: C
Question
Create a C# program with the following functionalities:
Input file (James bond, M ' jordan, and k smith)
(i) input file contains the people names in different lines (one name in one line)
(ii) input file contains only the first name and last name in this order
(iii) You program should read each person's name and write it to the "residents.txt" in 21 character lines where the last character would the the ' '
(iv) Your program should also print out the number of people processed.
(v) You may use the standard library functions such as fscanf to read, but should use the "write" system call to write to the residents.txt
Explanation / Answer
using System;
using System.IO;
namespace FileHandlingArticleApp
{
class Program
{
static void Main(string[] args)
{
int count=0;
if(File.Exists("test.txt"))
{
string content = File.ReadAllText("test.txt");
while (true)
{
var line = content .Readline();
if(line !=null)
{
count++;
}
else
{
break;
}
}
Console.WriteLine("Current content of file:");
Console.WriteLine(content);
Console.WriteLine("the total number of count ");
Console.WriteLine(couny);
}
Console.WriteLine("Please enter new content for the file:");
string newContent = Console.ReadLine();
File.WriteAllText("test.txt", newContent);
}
}
}