By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

warning no new line at end of the file

P: 1
#define NUMBEROFDICE 5
#include <stdio.h>
#include <stdlib.h>


void RollDice(int dice[])
{
int i;
for(i=0;i<NUMBEROFDICE;i++)
{
dice[i]=(rand() % 6)+1;
}
}
int main(void)
{
int dice[5];

RollDice(dice);
int i;
for(i=0;i<5;i++)
{
printf("%d/n",dice[i]);

}
return 0;
}
4 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


dev7060
100+
P: 114
Simply put, a newline is required at the end of a source file to not mess up things. Here's what happens: The #include preprocessor directive adds the content of the included file to the current file as it is. For e.g.
If a file called abc.h has content:

Sample Data(no newline)

And another file say program.c includes this file as:

#include "abc.h"
#include "second.h"

It would literally mean:

Sample Data#include "second.h"

Now imagine if there's a comment at the end of abc.h file. Then program.c would be:

//Sample Data#include "second.h"

Here, the second include statement is no longer effective. Therefore, newline is added to avoid these. Most text editors automatically put it at the end of the last line.
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.