Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:56:49+00:00 2026-06-15T06:56:49+00:00

I have defined subtype String10 is String(1..10); and I am attempting to get keyboard

  • 0

I have defined

subtype String10 is String(1..10);

and I am attempting to get keyboard input to it without having to manually enter whitespace before hitting enter. I tried get_line() but from some reason it wouldn’t actually wait for input before outputting the get put() command, and I also think it will just leave whatever was in the string before there and not fill it with white space.

I know about and have used Bounded_String and Unbounded_String, but I am wondering if there is a way to make this work.

I’ve tried making a function for it:

--getString10--
procedure getString10(s : string10) is
   c : character;
   k : integer;
begin
   for i in integer range 1..10 loop
      get(c);
      if Ada.Text_IO.End_Of_Line = false then
         s(i) := c;
      else
         k := i;
         exit;
      end if;
   end loop;

   for i in integer range k..10 loop
      s(i) := ' ';
   end loop;
end getString10;

but, here, I know the s(i) doesn’t work, and I don’t think the

"if Ada.Text_IO.End_Of_Line = false then" 

does what I’m hoping it will do either. It’s kinda just a placeholder while I look for the actual way to do it.

I been searching for a couple hours now, but Ada documentation isn’t as available or clear as other languages. I’ve found a lot about getting strings, but not what I’m looking for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:56:50+00:00Added an answer on June 15, 2026 at 6:56 am

    Just pre-initialize the string with spaces before calling Get_Line.

    Here’s a little program I just threw together:

    with Ada.Text_IO; use Ada.Text_IO;
    procedure Foo is
        S: String(1 .. 10) := (others => ' ');
        Last: Integer;
    begin
        Put("Enter S: ");
        Get_Line(S, Last);
        Put_Line("S = """ & S & """");
        Put_Line("Last = " & Integer'Image(Last));
    end Foo;
    

    and the output I get when I run it:

    Enter S: hello
    S = "hello     "
    Last =  5
    

    Another possibility, rather than pre-initializing the string, is to set the remainder to spaces after the Get_Line call:

    with Ada.Text_IO; use Ada.Text_IO;
    procedure Foo is
        S: String(1 .. 10);
        Last: Integer;
    begin
        Put("Enter S: ");
        Get_Line(S, Last);
        S(Last+1 .. S'Last) := (others => ' ');
        Put_Line("S = """ & S & """");
        Put_Line("Last = " & Integer'Image(Last));
    end Foo;
    

    For very large arrays, the latter approach might be more efficient because it doesn’t assign the initial portion of the string twice, but in practice the difference is unlikely to be significant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined this function that takes a word and a string of required
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have defined CSS in MasterPage so that all pages can use the same
I have defined a table type PL/SQL variable and added some data there. create
I have defined a rectangle drawable like this: <shape xmlns:android=http://schemas.android.com/apk/res/android android:shape=rectangle> <corners android:radius=4dip/> <solid
I have defined an array like so : var myArray = {myNewArray: ['string1' ,
I have defined many constants in GlobalVar.h and other .h files. I import these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.