Reputation: 33
How do I store the ascii value of an integer (say 33) in a character. I want something like this in Ada83, not 95
C: Code
char c = 10;
char *k = &c;
strncat (des, k, 1);
printf("%s",des);
Thank you!!
Upvotes: 2
Views: 2494
Reputation: 31699
C : Character := Character'Val(10);
or
C : Character := ASCII.LF;
The first works in all versions of Ada. The second one was the standard way in Ada 83; it is now obsolescent. The newer way is
C : Character := Ada.Characters.Latin_1.LF;
More information: In Ada, Character
is an enumeration type, not an integer type. Therefore, you can't assign an integer to it directly. The 'Val
attribute is the Ada way to convert an integer to an enumeration; Enum_Type'Val(N)
means "the Nth enumeration literal defined for the enumeration type, 0-relative". To go the other way, Enum_Type'Pos(E)
returns the integer corresponding to the position of E
in the enumeration list.
Upvotes: 3