Hi folks, I've a problem when writing the contents of a file that was read using steam reader to the console window. It is only displaying part of the information that it should be showing. It should be displaying like this:

http://i1370.photobucket.com/albums/ag266/Aaron_McCauley/1_zps4b8c3625.png

But insted it displays like so (Notice the cursor jumps ahead about 5 lines):

http://i1370.photobucket.com/albums/ag266/Aaron_McCauley/2_zps7f0e6259.png

Anyone no of a fix? Heres the code of the method:

 //Searching by Town

        static void FindTown(CustomerStruct[] CustomerDeats)
        {
            string City;
            bool CityMatch = false;
            Console.Clear();

        begin:
            try
            {
                Console.WriteLine("Please enter the customers Town ");
                City = Console.ReadLine();                
            }
            catch
            {
                Console.WriteLine("Failed. Please try again.");
                goto begin;
            }

            var pathToTown = @"..\..\..\Files\Customer.txt";

            using (StreamReader sr = new StreamReader(pathToTown))

                while (!CityMatch)
                {

                    {
                        RecCount = 0;

                        CustomerDeats[RecCount].Town = sr.ReadLine();

                        if (City == CustomerDeats[RecCount].Town)
                        {
                            CityMatch = true;

                            Console.Clear();

                            CustomerDeats[RecCount].CustomerNo = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].CustomerNo);

                            CustomerDeats[RecCount].Surname = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].Surname);

                            CustomerDeats[RecCount].Forename = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].Forename);

                            CustomerDeats[RecCount].Street = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].Street);

                            CustomerDeats[RecCount].Town = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].Town);

                            CustomerDeats[RecCount].DOB = sr.ReadLine();
                            Console.WriteLine(CustomerDeats[RecCount].DOB);

                            Console.ReadKey();
                        }

                        RecCount++;

                    }

                }
        }

What is the data in the file 'Customers.txt' and what did you type in?

The data in Customers.txt is customers data it is stored there using stream writer in another method. Here is the data file and all of its contents

1000
McNamee
Ben
5 Carnhill
Omagh
30/05/1991

1001
Gilmour
Ryan
10 Nelson Drive
London Derry
20/09/1991

1002
McCauley
Aaron
8 Sandale park
Derry
30/09/1991

I ran the program and wanted to search by town, so I typed in 'Derry'. Which should have picked up customer 1002 and displayed their info but it only displays their DOB. Furthermore when I search 'London Derry' this is the result, (picks up Correct Customers DOB but nothing else then the wrong customers name is also displayed):

http://i1370.photobucket.com/albums/ag266/Aaron_McCauley/3_zps1192f72d.png

Why dont you put your struct in the code so that others can directly copy and paste to VS...

The reason is that your code looks for a match on the city, then assumes everything AFTER that is part of the record. It isn't. You should read in a full record, then check the name and make sure you know which line goes with which property.

commented: I was looking at the code but missed that ;). You are 100% right as always. +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.