ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Read RMS voltage Register!
00980C7E
0.5939
Actual voltage!
237.5762
Read RMS current Register!
0002AEE6
0.0104
Actual current!
0.0873
Read status Register!
007FC3BC
Read RMS voltage Register!
009805E8
0.5938
Actual voltage!
237.5360
Read RMS current Register!
0002AF74
0.0104
Actual current!
0.0874
Read status Register!
007FC2D6
Read RMS voltage Register!
0097F7F8
0.5936
Actual voltage!
237.4509 ---------------------------> (i need this value)
Read RMS current Register!
0002ACE0
0.0104
Actual current!
0.0870 ------------------------> (i need this value)
Read status Register!
00920089
how do i write a c++ program to get the values?
as this text file kept updating, i need to always get the newest value (which values are insert at the bottom) will it affect the updating of the text file?
What do you mean by "extract the last few lines"? Simply get the last <n> lines? Or do you want to parse them to get the data?
Also, it it really necessary to do this in C++ (that is, this is part of a larger C++ program)? Or can it also be done using shell scripting, which would probably be simpler?
the latest values are at the bottom of the text file so i need the values. i only needed 2 values, the line after "Actual voltage!" and "Actual current!".
ya this is part of a large program, so i need to use c++.
The tail command does exactly what your requirements specify. If you need to do this with your own code, it shouldn't be too hard to see how tail does it. I'm pretty sure tail is part of the binutils package, if you want to track down the sources.
--- rod.
Yes, coreutils is the correct package; thanks to Nylex for the correction. The definitive link for info would be the GNU coreutils website, or more specifically, the page for the tail utility.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.