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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am messing around with cpp and I typed up this simple code:
// first C++ program
#include <iostream.h>
int main ()
{
cout <<" Hello World!";
return 0;
}
Then I do cpp test.cpp
and lots of stuff flies by on the screen and I get the error: test.cpp:9:2: warning: no newline at end of file.
should I be using something else other than cpp progname.cpp?
Is there a way to do away with this errror?
I am using cpp version 3.3.4
Thanks.
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,783
Rep:
It's not an extra new-line, each line should be terminated by an "end of line" tag, and this is \n under unix.
On MacOS, this used to be \r, perhaps the reason why gcc is more tolerant on newer releases of this O/S.
There's probably still some ancient compilers out there (maybe even very old versions of GCC?) that want each line to end with a newline or else they crash. My guess is that GCC is just trying to help you make your code compatible with these dino's.
If you have a compiler that doesn't warn you about the lack of a newline character then that compiler doesn't meet the standards. Burn the disc it came on and get a real compiler.
I developed some software which had to receive a configuration file via a socket connection... but the software which generated the file did not include a newline at the end - no big deal, right? They had accounted for this, and to indicate 'no more config entries' the last line was "99=0"...
The non-newline EOF was not documented, so I happily tried the following:
Code:
Socket socket = new Socket(hostName, portNumber);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String input;
while(!(input = bufferedReader.readLine()).equals("99=0")) {
// ... process the input
}
... which would block while waiting for the elusive newline until the socket connection finally timed out - which took way too long - so I called their technical support and they were at a loss as well... I finally fixed it by swapping out the above while loop with following code:
Code:
InputStream input = socket.getInputStream();
String response = "";
byte NEWLINE = (byte) '\n';
boolean getMoreData = true;
while (getMoreData) {
String temp = "";
byte subTemp = (byte)0;
while(subTemp != NEWLINE)
subTemp = (byte)input.read();
temp += new String(new byte[]{subTemp}, "UTF-8");
if(("99=0".equals(temp))){
getMoreData = false;
temp += new String(new byte[]{NEWLINE}, "UTF-8");
}
response += temp;
}
//break out the parts of the response
String[] split = response.split("\n");
for(String inputLine:split){
// ... process the input
}
Last edited by cr0ck3t; 05-12-2014 at 12:14 PM.
Reason: should not try to modify code in my head and then post without debugging first...
Come with me, back to the days of Yore, back to the days which I remember!
(and nay, I do not apologize for those memories ... "sorry you missed it")
In those grand old days of ASCII, there were two characters which controlled the teletype(!) and DECWriterterminals of those days: CR = Carriage Return (Chr(12)) and LF = Line Feed (Chr(10)). Technically, both characters were required by the equipment. However, in actual practice, sometimes it was one, sometimes it was the other, and sometimes it was both (in either order).
And, as time marched on (and computer programmers, as usual, could never quite decide ...) all four possibilities wound up sticking around for the next X decades.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.