warning no new line at end of the file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khatiwalaforam
    New Member
    • Sep 2019
    • 1

    warning no new line at end of the file

    #define NUMBEROFDICE 5
    #include <stdio.h>
    #include <stdlib.h>


    void RollDice(int dice[])
    {
    int i;
    for(i=0;i<NUMBE ROFDICE;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;
    }
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    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.

    Comment

    Working...