C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-30-2004, 11:25 AM   #1
Utter insanity
 
Join Date: Jan 2004
Posts: 19
"No newline at end of file"???

I'm still on chapter 6 (gotta wait until payday to get a new book...) and I'm doing the exercises. The first 4 have you creating a class Employee with three data members, methods to access them, ect... I get the warning "1 E:\Cpp\Source\e61a5.cpp:60 [Warning] no newline at end of file " when I try to compile. I would prefer to treat warnings as errors, since I know it may cause something I don't want, and later on down the line I don't want to be digging through 3 million lines looking for a bug that occured only because I ignored a warning in an earleir build... I'll post the code if y'all want; it's somewhat long, and otherwise error free. Thanks again.
__________________
"I merely took the energy it takes to pout and wrote some blues." - Duke Ellington
domhnall4h is offline   Reply With Quote
Old 12-30-2004, 11:34 AM   #2
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,291
Just taking a wild stab at it here...maybe you need a newline at the end of your file e61a5.cpp. Then again, I've never used your compiler.
__________________
Rule #1: Every rule has exceptions
pianorain is offline   Reply With Quote
Old 12-30-2004, 11:36 AM   #3
C Programmer
 
Stack Overflow's Avatar
 
Join Date: Apr 2004
Posts: 477
Hello,

I believe that warning exists to avoid empty source files and make sure the file contains at least a newline at the end of the file.
Code:
newline not last character in file
	Type: Warning
	Every non-empty source file and header must consist of complete lines.
	This diagnostic warns that the last line of a file did not end with a newline.
You can simply fix this warning by adding a new line at the end of your source file(s) and header file(s).


- Stack Overflow
__________________
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Stack Overflow is offline   Reply With Quote
Old 12-30-2004, 11:37 AM   #4
Utter insanity
 
Join Date: Jan 2004
Posts: 19
I tried putting an additional newline at the end of main; but not outside of it. Maybe that'll fix it. Thanks.

This compiler is supposedly ASCI standard; but then, so is my book; and I've ran over enough screwups (that I can see; and fix somewhat) that I'm beginning to think SAM's dosn't have an editorial dept. I'd reinstall borland, but my CD-RW is overheating. I'm afraid it will eat the disc.

edit: I didn't see stack's post before I posted. There is a newline character at the end of the last line of main. I added another one next to it and it did nothing. I also added a seperate cout statement at the end of main, with nothing but a \n in it; didn't help. adding a cout statement with just the newline char to the class just caused an error. This is the code as of the last adjustment; which removed the error and added several \n chars to the end of the thing.

Code:
#include <iostream>
using namespace std;

class Employee
{
      public:
              //Using default constructor/destructor
              //public data
              int ageX;
              int yearX;
              int SalX;
              //Accesor methods
              int getAge()const   { return ageX;}
              int getYears()const { return yearX; }
              int getSal()const   { return SalX; }
              //Data entry methods
              void setAge(int age) { ageX = age; }
              void setYears(int yearsOfService) { yearX = yearsOfService; }
              void setSal(int Salary) { SalX = Salary; }
              //Rounding employees' salary
              int getRoundedSal()const  { return (Salary+500) / 1000; }
      private:
              //private data
              int age;
              int yearsOfService;
              int Salary;
             
};

int main()
{
    //Employees
    Employee Frank;
    Employee Joe;
    //Employees' age
    Frank.setAge (21);
    Joe.setAge (19);
    //Employees' years of service
    Frank.setYears (3);
    Joe.setYears (2);
    //Employees' salary setting
    Frank.setSal (24762);
    Joe.setSal (23944);
    //Employees' Salary records
    cout << "Frank Hardy\n";
    cout << "Frank is " << Frank.getAge() << " and has been working here ";
    cout << Frank.getYears() << " years.\n";
    cout << "Frank makes " << Frank.getSal() << " dollars; which is ";
    cout << Frank.getRoundedSal() << " rounded off.\n";
    cout << "\n\n";
    
    cout << "Joe Hardy\n";
    cout << "Joe is " << Joe.getAge() << " and has been working here ";
    cout << Joe.getYears() << " years.\n";
    cout << "Joe makes " << Joe.getSal() << " dollars; which is ";
    cout << Joe.getRoundedSal() << " rounded off.\n\n";
    cout << "\n\n\n\n\n";
    return 0;
}
__________________
"I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

Last edited by domhnall4h; 12-30-2004 at 11:47 AM.
domhnall4h is offline   Reply With Quote
Old 12-30-2004, 12:01 PM   #5
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
You don't need a newline in the output. You need a newline in your actual code. Go to the } that ends main() and hit Enter
Thantos is offline   Reply With Quote
Old 12-30-2004, 12:04 PM   #6
C Programmer
 
Stack Overflow's Avatar
 
Join Date: Apr 2004
Posts: 477
Hello,

By adding a new line, I was referring to the carriage return. Like pressing the enter key at the last line of your file. For instance:

// Wrong
[code begin]
int main() {

}
[code ends here]

// Right
[code begin]
int main() {

}

[code ends here]

Simply hit the return key at the last line of your file. In this case, I'm guess the last line of your file ends with the }. Rather it should end with a blank line, a new line.


- Stack Overflow
__________________
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Stack Overflow is offline   Reply With Quote
Old 12-30-2004, 12:11 PM   #7
Utter insanity
 
Join Date: Jan 2004
Posts: 19
"1 E:\Cpp\Source\e61a5.cpp:64 [Warning] no newline at end of file"

That's with the extra line at the end of main. I'm beginning to believe this is a bug within the compiler's current version. this is the first prog I'll have compiled since I updated it. I'm going to check against some of the older progs that did compile fine previously, and see if it pops up.

The closing brace for main is on line 59. the file ends on line 68.

Thanks y'all.
__________________
"I merely took the energy it takes to pout and wrote some blues." - Duke Ellington
domhnall4h is offline   Reply With Quote
Old 12-30-2004, 12:24 PM   #8
Registered User
 
Join Date: Dec 2004
Posts: 73
If you're using Dev-C++, I have always gotten the newline warning. My programs ran just fine with it, so I don't think there is anything to worry about.
ElWhapo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help! Placement of nodes in a Linked List lostmyshadow C Programming 6 12-17-2007 01:21 PM
how to obtain first character of every other word archie C++ Programming 8 02-18-2002 01:58 PM
Collision with quads? SyntaxBubble Game Programming 6 01-18-2002 06:17 PM
Character in Array to end for loop. mattz C Programming 6 12-04-2001 11:05 AM
fgets and a bothersome newline char ivandn Linux Programming 1 11-14-2001 01:41 PM


All times are GMT -6. The time now is 12:04 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22