What I want is to define an array of Strings in Ada.

I'm trying to execute this code:

```
type String is array (Positive range <>) of Character;
type lexicon is array(1..7) of String(1..20);
nomFumadors : lexicon := ("Macia","Xisco","Toni","Laura","Rocky","Paz");
nomNoFumadors : lexicon := ("Marina","Marta","Joan","Africa","America");

```

And the compiler says:

```
warning:wrong length for array of subtype of "String" defined at line 42

```

My line 42 is this:

```
type lexicon is array(1..7) of String(1..20);

```

But compailer says the warning is in line 43 and 44: what are these:

```
nomFumadors : lexicon := ("Macia","Xisco","Toni","Laura","Rocky","Paz");
nomNoFumadors : lexicon := ("Marina","Marta","Joan","Africa","America");

```

Can somebody help me with that?
['https://Stackoverflow.com/questions/70968102', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12058857/']
You declared your array to hold Strings of length 20. The String literals you give are less than 20 Characters long. Hence the error.

You seem to be looking for a string type that contains a *maximum* of 20 characters. This is provided in `Ada.Strings.Bounded`:

```vhdl
package Max_20_String is new Ada.Strings.Bounded.Generic_Bounded_Length (20);
use Max_20_String;

type Lexicon is array (1..7) of Bounded_String; -- from Max_20_String
nomFumadors : Lexicon := (To_Bounded_String ("Macia"),
                          To_Bounded_String ("Xisco"),
                          To_Bounded_String ("Toni"),
                          To_Bounded_String ("Laura"),
                          To_Bounded_String ("Rocky"),
                          To_Bounded_String ("Paz"));

```

To get back a String from a Bounded\_String, use e.g. `To_String (Lexicon (2))`.
Another solution is to use String, truncate long strings, and pad short strings:

```
Max : constant := 20;
subtype S20 is String (1 .. Max);
type Lexicon is array (1 .. 7) of S20;
function To20 (S : in String) return S20 is
   (if S'Length >= Max then S (S'First .. S'First + Max - 1)
    else S & (S'Length + 1 .. Max => ' ') );
V : Lexicon := (To20 (""), To20 ("Hello"), To20 ("1234567890123456789012345"), ...

```