cfrank2000
Well-known member
- Joined
- Mar 6, 2021
- Messages
- 71
- Programming Experience
- Beginner
I try to read 'record data' from text file in a record list. unfortunately the loop not working and other things might not work, please help me, thank you, frank.
hotelorder1:
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace szalloda1
{
public class pitypang00
{
public int foglaloszam = 0;
public int szobaszam = 0;
public int erkezesinapsorszama = 0;
public int tavozasinapsorszam = 0;
public int vendegszam = 0;
public int kernekreggelit = 0;
public string vendegazonosito = " ";
}
class Program
{
static void Main(string[] args)
{
string olvas = @"c:\Users\Public\textfiles\pitypang.txt";
List<pitypang00> adatok = new List<pitypang00>();
int i = 0;
int i2 = 0;
int kod0 = 0;
int utolso = 0;
try
{
// Open the text file using a stream reader.
using (var sr = new StreamReader(olvas, Encoding.Default))
{
// Read the stream as a string, and write the string to the console.
//Console.WriteLine(sr.ReadToEnd());
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] record = sor.Split(' ');
adatok.Add(new pitypang00());
if (i == 0) { kod0 = Convert.ToInt32(record[0]); }
else
{
adatok[i].foglaloszam = Convert.ToInt32(record[1]);
adatok[i].szobaszam = Convert.ToInt32(record[2]);
adatok[i].erkezesinapsorszama = Convert.ToInt32(record[3]);
adatok[i].tavozasinapsorszam = Convert.ToInt32(record[4]);
adatok[i].vendegszam = Convert.ToInt32(record[5]);
adatok[i].kernekreggelit = Convert.ToInt32(record[6]);
adatok[i].vendegazonosito = record[7];
utolso++;
Console.WriteLine(i+" "+ record[7]);
i++;
}
}
sr.Close();
for (i2 = 1; i2 <= utolso; i2++){
Console.WriteLine(
" Foglaloszam "+ adatok[i].foglaloszam+
" Szobaszam "+ adatok[i].szobaszam+
" Erkezesinap\n sorszama "+ adatok[i].erkezesinapsorszama);
}
}
}
catch (IOException e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
Console.WriteLine(" Test "+utolso+ adatok[i].vendegazonosito);
}
}
}