The Ada Program: test.adb
1 with Interfaces.C; use Interfaces;
2 with Ada.Text_IO; use Ada;
3
4 procedure Test is
5
6 use type C.char_array;
7 -- Call <string.h>strcpy:
8 -- C definition of strcpy: char *strcpy(char *s1, const char *s2);
9 -- This function copies the string pointed to by s2 (including the terminating null character)
10 -- into the array pointed to by s1. If copying takes place between objects that overlap,
11 -- the behavior is undefined. The strcpy function returns the valueof s1.
12
13 -- Note: since the C function's return value is of no interest, the Ada interface is a procedure
14 procedure Strcpy (Target : out C.char_array;
15 Source : in C.char_array);
16
17 -- "strcpy" is found in libgnat.o which is linked in automatically
18 pragma Import (C, Strcpy, "strcpy");
19
20 Chars1 : C.char_array(1..20);
21 Chars2 : C.char_array(1..20);
22
23 begin
24 Chars2(1..6) := "qwert" & C.nul;
25 Strcpy(Chars1, Chars2);
26 -- Now Chars1(1..6) = "qwert" & C.Nul
27
28 Text_IO.Put_Line (C.To_Ada(Chars1) & "<<EOS>>");
29
30 end Test;