Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Project1.lpr(8,19) Fatal: Syntax error, ";" expected but "const string" found

GIST play Севостьянов Ученик (10), на голосовании 1 неделю назад
program PasswordGenerator;

uses
SysUtils, Classes;

const
AllowedChars = 'abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'0123456789'
'!@#$%^&*()';
PasswordLength = 12; // Length of the password

function GeneratePassword(Length: Integer): string;
var
i: Integer;
begin
Randomize; // Initialize the random number generator
SetLength(Result, Length);
for i := 1 to Length do
begin
Result[i] := AllowedChars[Random(Length(AllowedChars)) + 1]; // Generate a random character
end;
end;

procedure SavePasswordToFile(const Password: string; const FileName: string);
var
FileStream: TFileStream;
Bytes: TBytes;
begin
Bytes := TEncoding.UTF8.GetBytes(Password); // Convert the string to a byte array
FileStream := TFileStream.Create(FileName, fmCreate); // Create the file
try
FileStream.Write(Bytes[0], Length(Bytes)); // Write the password to the file
finally
FileStream.Free ; // Free resources
end;
end;

var
Password: string;
FileName: string;

begin
Password := GeneratePassword(PasswordLength); // Generate the password
Writeln('Generated Password: ', Password); // Output the generated password

FileName := 'password.txt'; // The filename to save the password
SavePasswordToFile(Password, FileName); // Save the password to the file

Writeln('Password saved to ', FileName); // Confirmation of saving
end.
Голосование за лучший ответ
Похожие вопросы