Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize string in Ada with null characters

Tags:

ada

gnat

I am new to Ada, I need to make initialize a string with null characters, how can I do it? So far I can initialize a string with spaces as follows:

user_str : String(1..50) := (others => ' ');
like image 371
SD. Avatar asked Feb 10 '26 22:02

SD.


1 Answers

user_str : String(1..50) := (others => Character'Val(0));

or

user_str : String(1..50) := (others => Ada.Characters.Latin_1.NUL);

Unlike some other languages, Ada does not have a special syntax for embedding speclal characters in character or string literals (like C's '\0', for example).

(Of course the latter requires an appropriate with clause.)

like image 151
Keith Thompson Avatar answered Feb 18 '26 13:02

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!