Simple ada program producing erroneous blank lines using get_line() and put_line()How can I read piped input in Perl on Windows?Specifying different platform specific package at compile time in Ada (GNAT)Reading text files in Ada: Get_Line “reads” the byte-order mark as wellProgrammatic interface to the GNAT compiler?How to loop through multiple data sets from standard inputAda Get_Line not waiting to get ResponseAda- attempting to remove blank spaces from a string?Ada: Why does my queue only hold it's value value in the loop?How can I pass command line arguments to the executable built by Gnat-GPS's Build>Run command?Ada programming. What is the difference between Put and Put_line
Why do we need to use transistors when building an OR gate?
Do the villains know Batman has no superpowers?
Debussy as term for bathroom?
Very lazy puppy
EU compensation - fire alarm at the Flight Crew's hotel
I was cheated into a job and want to leave ASAP, what do I tell my interviewers?
Tips for remembering the order of parameters for ln?
Is “卧草” a proper Chinese word?
Applications of mathematics in clinical setting
What is the word for a person who destroys monuments?
What is the maximum viable speed for a projectile within earth's atmosphere?
How do you determine which representation of a function to use for Newton's method?
Dear Fellow PSE Users,
Why are two-stroke engines nearly unheard of in aviation?
Can Brexit be undone in an emergency?
Floating Point XOR
Other than good shoes and a stick, what are some ways to preserve your knees on long hikes?
How does one calculate the distribution of the Matt Colville way of rolling stats?
How is underwater propagation of sound possible?
Why are there two bearded faces wearing red hats on my stealth bomber icon?
Prove that the area of the trangles are equal.
Integrability of log of distance function
Is it possible that the shadow of The Moon is a single dot during solar eclipse?
Weapon class firing logic in JavaScript
Simple ada program producing erroneous blank lines using get_line() and put_line()
How can I read piped input in Perl on Windows?Specifying different platform specific package at compile time in Ada (GNAT)Reading text files in Ada: Get_Line “reads” the byte-order mark as wellProgrammatic interface to the GNAT compiler?How to loop through multiple data sets from standard inputAda Get_Line not waiting to get ResponseAda- attempting to remove blank spaces from a string?Ada: Why does my queue only hold it's value value in the loop?How can I pass command line arguments to the executable built by Gnat-GPS's Build>Run command?Ada programming. What is the difference between Put and Put_line
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've been having this issue in a larger program, so I made a new ada program to test it and I get the same thing.
I have a text file (Unix line endings) as so:
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
What I want to do with it is simple, put each line in a string and then just print it right back out.
this is my code:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
input: String(1..18);
len: Natural;
begin
while not End_Of_File loop
Get_Line(input, len);
Put_Line(input(1..len));
end loop;
end Read;
Easy right? it takes in each line with get_line, saves it to "input" variable, and then prints out whatever amount of it was read in (using the length returned from get_line().
Unfortunately, I get a bunch of blank lines when I run this code:
gnatmake read read.adb
read < input.txt
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
I have gone through and made sure I dont have any weird line ending characters in my input file or anything like that (I just typed them out in vim).
This is messing up my program, because i have to account for these erroneous empty lines.
Any idea what I'm doing wrong here?
stdin ada
add a comment
|
I've been having this issue in a larger program, so I made a new ada program to test it and I get the same thing.
I have a text file (Unix line endings) as so:
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
What I want to do with it is simple, put each line in a string and then just print it right back out.
this is my code:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
input: String(1..18);
len: Natural;
begin
while not End_Of_File loop
Get_Line(input, len);
Put_Line(input(1..len));
end loop;
end Read;
Easy right? it takes in each line with get_line, saves it to "input" variable, and then prints out whatever amount of it was read in (using the length returned from get_line().
Unfortunately, I get a bunch of blank lines when I run this code:
gnatmake read read.adb
read < input.txt
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
I have gone through and made sure I dont have any weird line ending characters in my input file or anything like that (I just typed them out in vim).
This is messing up my program, because i have to account for these erroneous empty lines.
Any idea what I'm doing wrong here?
stdin ada
add a comment
|
I've been having this issue in a larger program, so I made a new ada program to test it and I get the same thing.
I have a text file (Unix line endings) as so:
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
What I want to do with it is simple, put each line in a string and then just print it right back out.
this is my code:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
input: String(1..18);
len: Natural;
begin
while not End_Of_File loop
Get_Line(input, len);
Put_Line(input(1..len));
end loop;
end Read;
Easy right? it takes in each line with get_line, saves it to "input" variable, and then prints out whatever amount of it was read in (using the length returned from get_line().
Unfortunately, I get a bunch of blank lines when I run this code:
gnatmake read read.adb
read < input.txt
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
I have gone through and made sure I dont have any weird line ending characters in my input file or anything like that (I just typed them out in vim).
This is messing up my program, because i have to account for these erroneous empty lines.
Any idea what I'm doing wrong here?
stdin ada
I've been having this issue in a larger program, so I made a new ada program to test it and I get the same thing.
I have a text file (Unix line endings) as so:
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
What I want to do with it is simple, put each line in a string and then just print it right back out.
this is my code:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
input: String(1..18);
len: Natural;
begin
while not End_Of_File loop
Get_Line(input, len);
Put_Line(input(1..len));
end loop;
end Read;
Easy right? it takes in each line with get_line, saves it to "input" variable, and then prints out whatever amount of it was read in (using the length returned from get_line().
Unfortunately, I get a bunch of blank lines when I run this code:
gnatmake read read.adb
read < input.txt
000_1000_0010_1001
100_0000_0010_1001
100_1000_0000_1001
100_1000_0010_0001
100_1000_0010_1001
000_0000_0011_0011
100_1000_0100
000_0000_0110
111_1111_1111
011_1111_1111
000_0000_0110
I have gone through and made sure I dont have any weird line ending characters in my input file or anything like that (I just typed them out in vim).
This is messing up my program, because i have to account for these erroneous empty lines.
Any idea what I'm doing wrong here?
stdin ada
stdin ada
edited Mar 28 at 14:13
egilhh
4,3571 gold badge11 silver badges19 bronze badges
4,3571 gold badge11 silver badges19 bronze badges
asked Mar 28 at 13:56
Sajid AnsariSajid Ansari
375 bronze badges
375 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
Your input
variable can hold 18 characters, and Get_Line
knows this, so when your input line is more than 18 characters long, it will read only 18 characters. It will then proceed to read the same line until either another 18 characters have been read, or the end of line has been reached. In your case, the input line is exactly 18 characters long (not counting the end of line), which just looks weird when the end of line is reached with no characters read into the input
variable (len
returns 0)...
You can either increase the length of your input
buffer to be bigger than any input you can think of, or let the runtime figure out how long the line is by using the function Get_Line return String;
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
begin
while not End_Of_File loop
declare
input : String := Get_Line;
begin
Put_Line(input);
end;
end loop;
end Read;
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
add a comment
|
In addition to egilhh answer,
First understand the background: there may be lines of text longer than the string provided, so line read is incomplete and it is required to call Get_Line
more than one time to read whole line.
To detect this case an application simply check if string is filled full, and read the rest. For this to work, Get_Line
treats the case of matched lengths as incomplete line, leaving 'rest' of line (0 chars) unread.
So, another solution exist:
while not End_Of_File loop
Get_Line(input, len);
if len < input'Last then
Put_Line(input(1..len)); -- whole (or the rest of previous) line read,
else
Put(input); -- (non-final) part of long line read, do not go to next
end if;
end loop;
or
while not End_Of_File loop
Get_Line(input, len);
Put(input(1..len)); -- do not emit eol yet...
if len < input'Last then
New_Line; -- now we know: line is finished
end if;
end loop;
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399395%2fsimple-ada-program-producing-erroneous-blank-lines-using-get-line-and-put-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your input
variable can hold 18 characters, and Get_Line
knows this, so when your input line is more than 18 characters long, it will read only 18 characters. It will then proceed to read the same line until either another 18 characters have been read, or the end of line has been reached. In your case, the input line is exactly 18 characters long (not counting the end of line), which just looks weird when the end of line is reached with no characters read into the input
variable (len
returns 0)...
You can either increase the length of your input
buffer to be bigger than any input you can think of, or let the runtime figure out how long the line is by using the function Get_Line return String;
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
begin
while not End_Of_File loop
declare
input : String := Get_Line;
begin
Put_Line(input);
end;
end loop;
end Read;
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
add a comment
|
Your input
variable can hold 18 characters, and Get_Line
knows this, so when your input line is more than 18 characters long, it will read only 18 characters. It will then proceed to read the same line until either another 18 characters have been read, or the end of line has been reached. In your case, the input line is exactly 18 characters long (not counting the end of line), which just looks weird when the end of line is reached with no characters read into the input
variable (len
returns 0)...
You can either increase the length of your input
buffer to be bigger than any input you can think of, or let the runtime figure out how long the line is by using the function Get_Line return String;
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
begin
while not End_Of_File loop
declare
input : String := Get_Line;
begin
Put_Line(input);
end;
end loop;
end Read;
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
add a comment
|
Your input
variable can hold 18 characters, and Get_Line
knows this, so when your input line is more than 18 characters long, it will read only 18 characters. It will then proceed to read the same line until either another 18 characters have been read, or the end of line has been reached. In your case, the input line is exactly 18 characters long (not counting the end of line), which just looks weird when the end of line is reached with no characters read into the input
variable (len
returns 0)...
You can either increase the length of your input
buffer to be bigger than any input you can think of, or let the runtime figure out how long the line is by using the function Get_Line return String;
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
begin
while not End_Of_File loop
declare
input : String := Get_Line;
begin
Put_Line(input);
end;
end loop;
end Read;
Your input
variable can hold 18 characters, and Get_Line
knows this, so when your input line is more than 18 characters long, it will read only 18 characters. It will then proceed to read the same line until either another 18 characters have been read, or the end of line has been reached. In your case, the input line is exactly 18 characters long (not counting the end of line), which just looks weird when the end of line is reached with no characters read into the input
variable (len
returns 0)...
You can either increase the length of your input
buffer to be bigger than any input you can think of, or let the runtime figure out how long the line is by using the function Get_Line return String;
:
with Ada.Text_IO; use Ada.Text_IO;
procedure Read is
begin
while not End_Of_File loop
declare
input : String := Get_Line;
begin
Put_Line(input);
end;
end loop;
end Read;
answered Mar 28 at 14:11
egilhhegilhh
4,3571 gold badge11 silver badges19 bronze badges
4,3571 gold badge11 silver badges19 bronze badges
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
add a comment
|
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
Specifically, the ARM says, "Reads successive characters from the specified input file and assigns them to successive characters of the specified string. Reading stops if the end of the string is met. Reading also stops if the end of the line is met before meeting the end of the string; in this case Skip_Line is (in effect) called with a spacing of 1." [ARM A.10.7(19) at ada-auth.org/standards/rm12_w_tc1/html/RM-A-10-7.html]. This is what other people have said in other words, but I thought the ARM reference might be useful.
– Jeffrey R. Carter
Apr 6 at 10:35
add a comment
|
In addition to egilhh answer,
First understand the background: there may be lines of text longer than the string provided, so line read is incomplete and it is required to call Get_Line
more than one time to read whole line.
To detect this case an application simply check if string is filled full, and read the rest. For this to work, Get_Line
treats the case of matched lengths as incomplete line, leaving 'rest' of line (0 chars) unread.
So, another solution exist:
while not End_Of_File loop
Get_Line(input, len);
if len < input'Last then
Put_Line(input(1..len)); -- whole (or the rest of previous) line read,
else
Put(input); -- (non-final) part of long line read, do not go to next
end if;
end loop;
or
while not End_Of_File loop
Get_Line(input, len);
Put(input(1..len)); -- do not emit eol yet...
if len < input'Last then
New_Line; -- now we know: line is finished
end if;
end loop;
add a comment
|
In addition to egilhh answer,
First understand the background: there may be lines of text longer than the string provided, so line read is incomplete and it is required to call Get_Line
more than one time to read whole line.
To detect this case an application simply check if string is filled full, and read the rest. For this to work, Get_Line
treats the case of matched lengths as incomplete line, leaving 'rest' of line (0 chars) unread.
So, another solution exist:
while not End_Of_File loop
Get_Line(input, len);
if len < input'Last then
Put_Line(input(1..len)); -- whole (or the rest of previous) line read,
else
Put(input); -- (non-final) part of long line read, do not go to next
end if;
end loop;
or
while not End_Of_File loop
Get_Line(input, len);
Put(input(1..len)); -- do not emit eol yet...
if len < input'Last then
New_Line; -- now we know: line is finished
end if;
end loop;
add a comment
|
In addition to egilhh answer,
First understand the background: there may be lines of text longer than the string provided, so line read is incomplete and it is required to call Get_Line
more than one time to read whole line.
To detect this case an application simply check if string is filled full, and read the rest. For this to work, Get_Line
treats the case of matched lengths as incomplete line, leaving 'rest' of line (0 chars) unread.
So, another solution exist:
while not End_Of_File loop
Get_Line(input, len);
if len < input'Last then
Put_Line(input(1..len)); -- whole (or the rest of previous) line read,
else
Put(input); -- (non-final) part of long line read, do not go to next
end if;
end loop;
or
while not End_Of_File loop
Get_Line(input, len);
Put(input(1..len)); -- do not emit eol yet...
if len < input'Last then
New_Line; -- now we know: line is finished
end if;
end loop;
In addition to egilhh answer,
First understand the background: there may be lines of text longer than the string provided, so line read is incomplete and it is required to call Get_Line
more than one time to read whole line.
To detect this case an application simply check if string is filled full, and read the rest. For this to work, Get_Line
treats the case of matched lengths as incomplete line, leaving 'rest' of line (0 chars) unread.
So, another solution exist:
while not End_Of_File loop
Get_Line(input, len);
if len < input'Last then
Put_Line(input(1..len)); -- whole (or the rest of previous) line read,
else
Put(input); -- (non-final) part of long line read, do not go to next
end if;
end loop;
or
while not End_Of_File loop
Get_Line(input, len);
Put(input(1..len)); -- do not emit eol yet...
if len < input'Last then
New_Line; -- now we know: line is finished
end if;
end loop;
answered Mar 30 at 13:30
VovaniumVovanium
3,25811 silver badges20 bronze badges
3,25811 silver badges20 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399395%2fsimple-ada-program-producing-erroneous-blank-lines-using-get-line-and-put-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown