Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Calling scanf from Ada
  2. with Ada.Text_IO; use Ada.Text_IO;
  3. with Interfaces.C; use Interfaces.C;
  4. procedure Variadic is
  5.    function Scanf (Fmt : char_array; Result : access int) return int;
  6.    pragma Import (C, Scanf, "scanf");
  7.    Status : int;
  8.    Result : aliased int;
  9. begin
  10.    Status := Scanf (To_C ("%dn"), Result'Access);
  11.    Put_Line ("status: " & int'Image (Status));
  12.    if Status = 1 then
  13.       Put_Line ("result: " & int'Image (Result));
  14.    end if;
  15. end Variadic;
  16.        
  17. int scanf_i(const char *format, int *i_ptr) {
  18.     return scanf(format, i_ptr);
  19. }
  20.  
  21. int scanf_d(const char *format, double *d_ptr) {
  22.     return scanf(format, d_ptr);
  23. }