I am unsure of what I am doing wrong here. It compiles and runs, and acts ok, but it is not writing the line into the text file. I have my FileStream and read on MSDN to try and figure this out on my own. When I did get something to work, it overwrote the entire file with what I put into it. So I am hoping maybe a programmer who has done this for more than 4 months (such as me) can explain. Here is a piece of my code that I think is relevant.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication33
{
class Program
{
static void Main(string[] args)
{
FileStream FireBall = new FileStream("Students.txt", FileMode.Open, FileAccess.Read);
StreamReader inFile = new StreamReader(FireBall);
string inValue;
string[] values;
double GPA;
double total = 0;
double counter = 0;
double count = 0;
double counti = 0;
double counterr = 0;
List<string> Anderson = new List<string>(); //Anderson
List<string> gpa = new List<string>(); //GPA
List<string> noemail = new List<string>(); // email
List<string> lines = new List<string>();
string newLastName = "'Constant";
string newRecord = "(LIST (LIST 'Constant 'Malachi 'D ) '1234567890 'mdconstant@mail.usi.edu 4.000000 )";
string line;
string lastName;
bool insertionPointFound = false;
for (int i = 0; i < lines.Count && !insertionPointFound; i++)
{
line = lines[i];
if (line.StartsWith("(LIST (LIST "))
{
values = line.Split(" ".ToCharArray());
lastName = values[2];
if (newLastName.CompareTo(lastName) < 0)
{
lines.Insert(i, newRecord);
insertionPointFound = true;
}
}
}
if (!insertionPointFound)
{
lines.Add(newRecord);
}