Read in numbers from console won't stop at newline.
Hello,
I have snippet code from Lippman's <<C++ primer>>.
The program is to convert regular decimal (0 ~ 15) numbers to basic hexdecimals. The instruction tells the program will execute by hitting newline at the end. When I tried to run the compiled program, hitting ENTER did not work as instructed in the book. I have to hit any invalid letter/key or Ctrl+D (I'm using Ubuntu) to terminate the input.
Exact same question was asked in stackoverflow,
1) which used getline() and I can't get the logic flow and the posted code did not work as expected; and
2) it seems there may be better way for this basic trick.
My question is what is the best practice to stop reading space-delimited numbers at newline instead of Ctrl+D or by hitting any invalid char?
Thanks!
Last edited by yifangt; 01-24-2018 at 05:24 PM..
Reason: typos and reformat
Hi Folks,
I have been trying to create a script wherein after it reads a certain number of data, it will pause and ask the user if he wants to continue or not. However, it seems that when it is supposed to read the user's answer, the script will go into a loop. What is wrong with my script here?... (7 Replies)
I am stuck with a problem while reading data from a file..
while
do
read line
#do some operations and if some condition is satisfied, ask the user to enter his choice.
# using the choice continue operations.
done < fileBeingRead.txt
The... (4 Replies)
I've installed Solaris 10 (x86 8/07) on a Dell PowerEdge 2950. When I bring up the Solaris Management Console I get red stop sign looking icons on all areas (System Status, System Configuration, Services, Storage, and Devices and hardware) under This computer. Originally nothing was showing up... (1 Reply)
Howdy experts,
We have some ranges of number which belongs to particual group as below.
GroupNo StartRange EndRange
Group0125 935300 935399
Group2006 935400 935476
937430 937459
Group0324 935477 935549
... (6 Replies)
Hi,
Sun Solaris. I am working on the console, I have pulled the network cable out. I am in the process of changing the IP address and few others thing. But this message comes every few seconds.
SUNW,hme0: Link Down - cable problem?
SUNW,hme0: Link Down - cable problem?
It's very... (2 Replies)
Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have:
... (4 Replies)
Hi Guys,
Happy New Year to you all!
I have a requirement to read an embedded new-line using KSH's read builtin.
Here is what I am trying to do:
run_sql "select guestid, address, email from guest" | while read id addr email
do
## Biz logic goes here
done
I can take care of any... (6 Replies)
Hey guys,
How do I make a loop that reads all the parameters en then stop when there are no parameters anymore ?
Something that gives an output like this:
./Script.sh parameter1 parameter2 parameter3
parameter = parameter1
parameter = parameter2
parameter = parameter3
Thanks a lot,... (5 Replies)
Hi all,
I'm installing a HP r2660 machine with HP-UX 11.23 (this version fixed by customer's product) and I've troubles using the VGA console as workstation display.
At first it worked just as TEXT console, then I fixed /etc/dt/config/Xservers and now I've the CDE prompt for login.
... (5 Replies)
I am using while read do/ done to retrieve menu item.
Works as advertised, no problem.
I am using this hack function "pause" to stop script execution and wait for keyboard "enter" key to continue. Sort of break point function. Also works fine with one exception - it does not work when used... (4 Replies)