hi,
this is the code:
#include <stdio.h>
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 <return> in the end of file 'after }' three times.
plz help me.


:-|

thekashyap commented: Just for creating such a famous thread.. :) +2

Recommended Answers

All 19 Replies

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]

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

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

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.

commented: Yes, thats exactly the reason behind it. +22

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.

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.. :)

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

: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..

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.

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

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 <stdio.h>
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 <return> in the end of file 'after }' three times.
plz help me.


:-|

i feel like i have touched history.

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.

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.

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

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!

commented: Your meaningless bump of a 5 year old thread is a pretty maddening issue. -4
commented: Next time you feel the need to grave dig, just use the "add reputation" to signify your thanks -6

hi,
this is the code:
#include <stdio.h>
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 <return> 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.

commented: useless bump of 5-year-old thread. -5
commented: And how many years did it take you to figure that one out? -3

I had the same problem, just hit 'Enter three times' at the end of your code. You will still get the warning but your program will compile. Just ignore the warning and run your program

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.