Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Char to String conversion Ada

I am trying to iterate through chars and print them using Put_Line() function but it takes String parameters, not chars. Is it possible to convert char to String like I can do it with Integer using 'Image()? My code:

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is

begin
  for I in 'A' .. 'Z' loop
    Put_Line(I);
  end loop;
end Main;
like image 708
Kuba Krzyżyński Avatar asked Jan 03 '23 07:01

Kuba Krzyżyński


1 Answers

Your problem is not only Character conversion but you need also to inform compiler what kind of Character you will use, and yes, you can use Image attribute to get String representation of a char.

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is

begin
   for I in Character range 'A' .. 'Z' loop
      Put_Line(I'Image);
   end loop;
end Main;

This code will work.

like image 91
Timur Samkharadze Avatar answered Jan 08 '23 11:01

Timur Samkharadze