ssr
ssr

Reputation: 33

How to store the ASCII value in a character (Ada 83 Only)

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

Answers (1)

ajb
ajb

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

Related Questions