1

After typing input from Integer it will automatically skip of getting the inputs from String. I don't know why?

Simple Ada code of getting inputs of String and Integer:

with ada.Text_IO; use ada.Text_IO;
with ada.Integer_Text_IO; use ada.Integer_Text_IO;
procedure Main is

   inputText: String (1..10);
   inputNmbr : Integer;
   StringNatural: Integer;  

begin

   Put_Line("Enter Integer");
   Get(inputNmbr,1);
   Put_Line("Enter String");
   Get_Line(inputText,StringNatural);
   Put_Line("===================");
   Put("Input for Integer: ");
   Put(inputNmbr,1);
   Put_Line("");
   Put_Line("Input for String: ");
   Put_Line(inputText(1..StringNatural));

end Main;

Output:

Enter Integer
2
Enter String
===================
Input for Integer: 2
Input for String: 

[2015-07-11 23:01:00] process terminated successfully, elapsed time: 00.86s
trashgod
  • 203,806
  • 29
  • 246
  • 1,045

1 Answers1

6

Get won't clear the keyboard buffer, so you're having a carriage return sent to Get_Line as input. You can put a Skip_Line after Get to fix this:

Put_Line("Enter Integer");
Get(inputNmbr,1);
Skip_Line; -- add this
Put_Line("Enter String");

Skip_Line documentation:

Skip_Line is an input procedure and will cause the input to skip to the next line. This is useful to remove the carriage return from the input buffer. Skip_Line should be performed after any call to a Get procedure. It can also be used to make a program pause and wait for a carriage return to be entered.

See also: Clearing the keyboard buffer in Ada

ipavl
  • 828
  • 11
  • 20