![]() |
| | #1 |
| Utter insanity Join Date: Jan 2004
Posts: 19
| "No newline at end of file"???
__________________ "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington |
| domhnall4h is offline | |
| | #3 |
| C Programmer 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. - 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 | |
| | #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 | |
| | #5 |
| & the hat of GPL slaying 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 | |
| | #6 |
| C Programmer 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 | |
| | #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 | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |