954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

warning:no newline at end of file

hi,
this is the code:
#include
main()
{
int m1, m2, m3, m4, m5, per;

printf("Enter marks in five subjects\n");
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);


per=(m1+m2+m3+m4+m5)/5;

if(per>=60)
printf("first division\n");

if((per>=50) && (per<60))
printf("second division\n");

if((per>=40) && (per<50))
printf("third division\n");

if(per<40)
printf("fail\n");

}

this is the output for:

[root@localhost lbin]# gcc -o division division.c
division.c:30:1: warning: no newline at end of file

The executable file division is runing successfully,just i want to know why there is the error 'no newline at the end of file' although i hit the in the end of file 'after }' three times.
plz help me.


:-|

abd2
Newbie Poster
3 posts since Jul 2004
Reputation Points: 13
Solved Threads: 0
 

Did you save it or did it automatically save after entering the 3 lines? [And next time, try to put your code between code tags ([code][/code]).]

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

I ran your program through my gcc compiler, i did not get any errors. so whats the problem? :cheesy:

nufanvandal
Newbie Poster
18 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
 

Hello,

I used the pico editor to cut your text, and paste them into my RedHat 9 box. Then closed the editor, and it compiled just fine.

Maybe you are using vi and left something in there. Or Emacs left something. I dunno. Try cat division.c and see if you see any junk in the file.

I do think, however, it is poor program design on two occasions:

* You are using an integer for the division. per = (M+M+M) / 5 What happens if I enter in decimal numbers?

* You are asking for input on one line. Will the computer accept typo corrections? I would input them one line at a time, so that if I do typo, I can correct it without deleting too much. You also do not check to make sure I enter in 5 values. What happens if I only put in four?

(I have tested these conditions. You should too).

Enjoy!

Christian

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

indeed :mrgreen:

nufanvandal
Newbie Poster
18 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
 

I realize that this thread is 2 years old, but it is the top search result for this error message, so maybe I will help a fellow newb.

If you are using the dev c++ enviroment,as I am, and probably other enviroments. The Error is caused by not hitting enter after the last line of code.

joshD
Newbie Poster
1 post since Jun 2007
Reputation Points: 32
Solved Threads: 0
 

Somewhere in the C compiler details it states that the code has to finish with a newline. Dev-Cpp's GNU compiler and some other compilers give a warning, not an error. Many IDEs put the new line in automatically.

vegaseat
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

Couldn't help but notice that unless there is some bug in daniweb.com this is most read thread I've seen so far.. ! 17,751 times.. :)

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 
Couldn't help but notice that unless there is some bug in daniweb.com this is most read thread I've seen so far.. ! 17,751 times.. :)

:cool: :sweat: you need to report that to Dani

Ancient Dragon
Retired & Loving It
Team Colleague
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 
:cool: :sweat: you need to report that to Dani

I donno where/how to tell her.. You're the moderator.. :) I understand you guys have some forums by yourselves..

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

No, this is no bug. Considering that the thread was started way back in 2004 and this is the most common warning message one encounters when using a gcc or g++ compiler, coupled with the fact that Daniweb is highly Search Engine Optimized site, it doesn't come as a surprise to me. :-)

Look at some other threads which were started in 2003 and 2004 and you would surely find most of them having more than 10K views.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

This thread is 3 years old, so it might have been read that many times!

vegaseat
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

Dude,

This just happened to me, only with MinGW, which uses the GNU compilers. I found that in my case, even though my file had plenty of newlines at the end of it, each newline had some whitespace prior to them because my editor was trying to be smart by indenting each of my lines. Once I removed the whitespace, the compiler no longer complained.

Hope this helps.
flippin_phil

hi, this is the code: #include main() { int m1, m2, m3, m4, m5, per;

printf("Enter marks in five subjects\n"); scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);

per=(m1+m2+m3+m4+m5)/5;

if(per>=60) printf("first division\n");

if((per>=50) && (per<60)) printf("second division\n");

if((per>=40) && (per<50)) printf("third division\n");

if(per<40) printf("fail\n");

}

this is the output for:

[root@localhost lbin]# gcc -o division division.c division.c:30:1: warning: no newline at end of file

The executable file division is runing successfully,just i want to know why there is the error 'no newline at the end of file' although i hit the in the end of file 'after }' three times. plz help me.

:-|

flippin_phil
Newbie Poster
1 post since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

i feel like i have touched history.

jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
 

It's part of the C89 and C99 standard to require a newline at the end a non-empty file so any C compiler that does not warn about it is not following the standard.

ohyeah
Light Poster
49 posts since Aug 2005
Reputation Points: 10
Solved Threads: 2
 
It's part of the C89 and C99 standard to require a newline at the end a non-empty file so any C compiler that does not warn about it is not following the standard.

Yes, you are right. According to 5.1.1.2.2 "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place". So, according to the C99 standard, programm, that don't have a new-line character at the end of each source file should not compile.

Tilir
Newbie Poster
14 posts since Jul 2008
Reputation Points: 46
Solved Threads: 2
 

Hi Just "Press Enter" after the last curly braces. you must be using vi editor. Some compilers show this as warning.

ahamed101
Junior Poster
117 posts since Jul 2008
Reputation Points: 51
Solved Threads: 14
 

I realize that this thread is 2 years old, but it is the top search result for this error message, so maybe I will help a fellow newb.

If you are using the dev c++ enviroment,as I am, and probably other enviroments. The Error is caused by not hitting enter after the last line of code.

Two years old or not this response really helped me out with a pretty maddening issue. :)

Thanks!

girliegeek0001
Newbie Poster
1 post since Apr 2009
Reputation Points: 0
Solved Threads: 0
 

hi, this is the code: #include main() { int m1, m2, m3, m4, m5, per;

printf("Enter marks in five subjects\n"); scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);

per=(m1+m2+m3+m4+m5)/5;

if(per>=60) printf("first division\n");

if((per>=50) && (per<60)) printf("second division\n");

if((per>=40) && (per<50)) printf("third division\n");

if(per<40) printf("fail\n");

}

this is the output for:

[root@localhost lbin]# gcc -o division division.c division.c:30:1: warning: no newline at end of file

The executable file division is runing successfully,just i want to know why there is the error 'no newline at the end of file' although i hit the in the end of file 'after }' three times. plz help me.

:-|

After the end of the } bracket just press enter to make new line and you wont get warning message for no newline at end of file.

kapas2004
Newbie Poster
1 post since Jun 2009
Reputation Points: 2
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You