using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FriendBirthdayReminder
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream file = new FileStream("FriendsData.txt", FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(file);

            const char DEMLIM = ',';
            const int END = 999;
            int count = 0,num,size;
            string name,recordIn;
            string[] fields;
            

            name = reader.ReadLine();
            fields = name.Split(DEMLIM);
            while (name != null)
            {
                ++count;
                name = reader.ReadLine();
                recordIn = reader.ReadLine();
            }
            size = (int)file.Length / count;

            Console.Write("\nEnter a Month ");
            num = Convert.ToInt32(Console.ReadLine());            
            
            while (num != END)
            {
                Console.WriteLine("People born in this month: ");
                file.Seek((size - 1) * size, SeekOrigin.Begin);
                name = fields[0] + " " + fields[1];
                Console.WriteLine("  " + name);
                while (name != null)
                {
                    name = reader.ReadLine();
                    Console.WriteLine("  " + name);
                }
                Console.Write("\nEnter a Month(Enter " + END + " to quit) ");
                num = Convert.ToInt32(Console.ReadLine());
            }
            reader.Close();
            file.Close();
        }
    }
}

when the user enters in s birthday month(number format) the program will display everyone who is born in the same month.

ex of the file

John,Doe,757-845-8658,12,26
first name, last name, phone number, birthday month, birthday day

can someone help me fix this?

where are you matching the birthmonth entered with the birthmonths already in the file? in my opinion you should match the entered month with already existing months by simply split the line into a string array and convert the month at array index 3 in integer and match with the entered month

This article has been dead for over six months. Start a new discussion instead.