Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Project9;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- Function SizeOfMatrix(var MyFile: TextFile) : Integer;
- var
- Numb, n, NumbEx, Temp:Integer;
- IsCorrect, FirstIt: Boolean;
- begin
- n := 0;
- FirstIt := True;
- IsCorrect := True;
- while (not Eof(MyFile)) and IsCorrect do
- begin
- NumbEx := Numb;
- Numb := 0;
- while not Eoln(MyFile) do
- begin
- Inc(Numb);
- Read (MyFile, Temp);
- end;
- if NumbEx <> Numb then
- IsCorrect := False;
- if FirstIt then
- begin
- IsCorrect := True;
- FirstIt := False;
- end;
- Inc(n);
- Readln(MyFile);
- end;
- if (Numb = n) and IsCorrect then
- SizeOfMatrix := n
- else
- SizeOfMatrix := 0;
- end;
- procedure ReadFileName (var MyFile: TextFile);
- var
- FName: string;
- CorrectName: boolean;
- begin
- Writeln ('Enter a file name for data entry in the format Name.txt');
- AssignFile(MyFile, FName);
- Reset(MyFile);
- begin
- repeat
- Readln(FName);
- if FileExists(FName) then
- CorrectName := True
- else
- begin
- Writeln ('The file name was entered incorrectly. Try again. Example: Name.txt');
- CorrectName := False;
- end;
- until CorrectName ;
- end;
- end;
- function IsTheMatrixCorrect(FName: string): boolean;
- var
- MyFile: TextFile;
- Number: Integer;
- TrueMatrix, IsValidInput: Boolean;
- begin
- TrueMatrix := True;
- AssignFile(MyFile, FName);
- reset(MyFile);
- while (not EOF(MyFile)) do
- begin
- try
- read(MyFile, Number)
- except
- TrueMatrix := false
- end;
- end;
- AssignFile(MyFile, FName);
- Reset(MyFile);
- if EoF(MyFile) then
- Writeln('File is empty.')
- else
- IsValidInput := True;
- CloseFile(MyFile);
- IsTheMatrixCorrect := TrueMatrix;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement