Velocity Reviews > Pesky Error

# Pesky Error

Guest
Posts: n/a

 03-19-2006
Could someone help me figure out why this error keeps occuring thanks
for the help.

error:
cc FordFulkerson.c
FordFulkerson.c:117:2: warning: no newline at end of file

Code:
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX_NODES 1000
#define oo 1000000000

//Declarations
int n; // number of nodes
int e; // number of edges
int capacity[MAX_NODES][MAX_NODES]; // capacity matrix
int flow[MAX_NODES][MAX_NODES]; // flow matrix
int color[MAX_NODES]; // needed for breadth-first search
int pred[MAX_NODES]; // array to store augmenting path

int min (int x, int y) {
return x<y ? x : y; // returns minimum of x and y
}

int q[MAX_NODES+2];

void enqueue (int x) {
q[tail] = x;
tail++;
color[x] = GRAY;
}

int dequeue () {
color[x] = BLACK;
return x;
}

//Breadth-First Search for an augmenting path
int bfs (int start, int target) {
int u,v;
for (u=0; u<n; u++) {
color[u] = WHITE;
}
enqueue(start);
pred[start] = -1;
u = dequeue();
// Search all adjacent white nodes v. If the capacity
// from u to v in the residual network is positive,
// enqueue v.
for (v=0; v<n; v++) {
if (color[v]==WHITE && capacity[u][v]-flow[u][v]>0) {
enqueue(v);
pred[v] = u;
}
}
}
// If the color of the target node is black now,
// it means that we reached it.
return color[target]==BLACK;
}

//Ford-Fulkerson Algorithm
int max_flow (int source, int sink) {
int i,j,u;
// Initialize empty flow.
int max_flow = 0;
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
flow[i][j] = 0;
}
}
// While there exists an augmenting path,
// increment the flow along this path.
while (bfs(source,sink)) {
// Determine the amount by which we can increment the flow.
int increment = oo;
for (u=n-1; pred[u]>=0; u=pred[u]) {
increment = min(increment,capacity[pred[u]][u]-flow[pred[u]][u]);
}
// Now increment the flow.
for (u=n-1; pred[u]>=0; u=pred[u]) {
flow[pred[u]][u] += increment;
flow[u][pred[u]] -= increment;
}
max_flow += increment;
}
// No augmenting path anymore. We are done.
return max_flow;
}

//Reading the input file and the main program
int a,b,c,i,j;
FILE* input = fopen("mf.in","r");
// read number of nodes and edges
fscanf(input,"%d %d",&n,&e);
// initialize empty capacity matrix
for (i=0; i<n; i++) {
for (j=0; j<n; j++) {
capacity[i][j] = 0;
}
}
for (i=0; i<e; i++) {
fscanf(input,"%d %d %d",&a,&b,&c);
capacity[a][b] = c;
}
fclose(input);
}

int main () {
printf("%d\n",max_flow(0,n-1));
return 0;
}

Again thanks for the help.

Guest
Posts: n/a

 03-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) opined:

> Could someone help me figure out why this error keeps occuring thanks
> for the help.
>
> error:
> cc FordFulkerson.c
> FordFulkerson.c:117:2: warning: no newline at end of file

For exactly the reason given in the error text.

The compiler expects a newline as the very last thing in the source
file. Just go to the very end of the file, hit <ENTER>, and it
disappears.

I don't the rational for this requirement. I also tend to see a lot of
this when copy/pasting code from Usenet articles.

<snip lots of code with no newline at the very end>

--

We should have a Vollyballocracy. We elect a six-pack of presidents.
Each one serves until they screw up, at which point they rotate.
-- Dennis Miller

Robert Gamble
Guest
Posts: n/a

 03-19-2006
(E-Mail Removed) wrote:
> Could someone help me figure out why this error keeps occuring thanks
> for the help.
>
> error:
> cc FordFulkerson.c
> FordFulkerson.c:117:2: warning: no newline at end of file

[snip over 100 lines of code]

You are missing the required newline at the end of your source file,
but I see how you might be confused from the overly cryptic error
message...

Robert Gamble

Skarmander
Guest
Posts: n/a

 03-19-2006
Robert Gamble wrote:
> (E-Mail Removed) wrote:
>> Could someone help me figure out why this error keeps occuring thanks
>> for the help.
>>
>> error:
>> cc FordFulkerson.c
>> FordFulkerson.c:117:2: warning: no newline at end of file

>
> [snip over 100 lines of code]
>
> You are missing the required newline at the end of your source file,
> but I see how you might be confused from the overly cryptic error
> message...
>

Well, for starters, what's a "newline", eh? Is it the same as a "new line"?
I don't actually see a new line when I add a newline, mind you. And, of
course, when you move your source files across platforms, you may have to
use new newlines.

And don't get me started about "end of file"...

S.

John F
Guest
Posts: n/a

 03-20-2006
> (E-Mail Removed) opined:
>
>> Could someone help me figure out why this error keeps occuring
>> thanks
>> for the help.
>>
>> error:
>> cc FordFulkerson.c
>> FordFulkerson.c:117:2: warning: no newline at end of file

>
> For exactly the reason given in the error text.
>
> The compiler expects a newline as the very last thing in the source
> file. Just go to the very end of the file, hit <ENTER>, and it
> disappears.
>
> I don't the rational for this requirement. I also tend to see a lot
> of
> this when copy/pasting code from Usenet articles.
>
> <snip lots of code with no newline at the very end>

I suppose the standard requires a source file to be a text file (which
seems to make some sense).

The only formal definition of what a text file is supposed to look
like is done by POSIX (AFAIK) and it _requires_ a text file to end
with a newline character.

References:
"IEEE Std 1003.1, 2004 Edition. The Open Group Technical Standard Base
Specifications, Issue 6." defines:
"3.392 Text file
A file that contains characters organised into one or more
lines.[...]"

and:

"3.205 Line
A sequence of zero or more non- <newline>s plus a terminating
<newline>."

thus:
- minimum of one line.
- line has to end with a "newline"
- line without newline is illegal

follows:
- a zero byte file can never be a text file.
- any file with a series of characters without
a newline at its end is not a text file.
- the last line in a text file must have a "newline" to be called a
line and to make it a text file.

--
regards
John

Jack Klein
Guest
Posts: n/a

 03-20-2006
On Mon, 20 Mar 2006 02:04:26 +0100, "John F" <spam@127.0.0.1> wrote in
comp.lang.c:

> > (E-Mail Removed) opined:
> >
> >> Could someone help me figure out why this error keeps occuring
> >> thanks
> >> for the help.
> >>
> >> error:
> >> cc FordFulkerson.c
> >> FordFulkerson.c:117:2: warning: no newline at end of file

> >
> > For exactly the reason given in the error text.
> >
> > The compiler expects a newline as the very last thing in the source
> > file. Just go to the very end of the file, hit <ENTER>, and it
> > disappears.
> >
> > I don't the rational for this requirement. I also tend to see a lot
> > of
> > this when copy/pasting code from Usenet articles.
> >
> > <snip lots of code with no newline at the very end>

>
>
> I suppose the standard requires a source file to be a text file (which
> seems to make some sense).
>
> The only formal definition of what a text file is supposed to look
> like is done by POSIX (AFAIK) and it _requires_ a text file to end
> with a newline character.
>
> References:
> "IEEE Std 1003.1, 2004 Edition. The Open Group Technical Standard Base
> Specifications, Issue 6." defines:
> "3.392 Text file
> A file that contains characters organised into one or more
> lines.[...]"
>
> and:
>
> "3.205 Line
> A sequence of zero or more non- <newline>s plus a terminating
> <newline>."
>
> thus:
> - minimum of one line.
> - line has to end with a "newline"
> - line without newline is illegal
>
> follows:
> - a zero byte file can never be a text file.
> - any file with a series of characters without
> a newline at its end is not a text file.
> - the last line in a text file must have a "newline" to be called a
> line and to make it a text file.

Has nothing at all to do with the POSIX standard, and everything to do
with the C standard, period:

"Each instance of a backslash character (\) immediately followed by a
new-line character is deleted, splicing physical source lines to form
logical source lines. Only the last backslash on any physical source
line shall be eligible for being part of such a splice. 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."

The C standard just plain requires that a source file end in a
new-line character, except for the degenerate case of an empty file.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Jordan Abel
Guest
Posts: n/a

 03-20-2006
On 2006-03-20, Jack Klein <(E-Mail Removed)> wrote:
> The C standard just plain requires that a source file end in a
> new-line character, except for the degenerate case of an empty file.

"...which it does not admit at all", I suspect you meant to say. I don't
even think a file ending in a newline but containing no declarations is
legal.

Jack Klein
Guest
Posts: n/a

 03-20-2006
On 20 Mar 2006 03:41:01 GMT, Jordan Abel <(E-Mail Removed)> wrote
in comp.lang.c:

> On 2006-03-20, Jack Klein <(E-Mail Removed)> wrote:
> > The C standard just plain requires that a source file end in a
> > new-line character, except for the degenerate case of an empty file.

>
> "...which it does not admit at all", I suspect you meant to say. I don't
> even think a file ending in a newline but containing no declarations is
> legal.

Let me repost the actual quoted text from the standard, which you
snipped:

"Each instance of a backslash character (\) immediately followed by a
new-line character is deleted, splicing physical source lines to form
logical source lines. Only the last backslash on any physical source
line shall be eligible for being part of such a splice. 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."

....since the standard obviously allows for the existence of an empty
source file, and allows such a source file to be completely empty,
exempting it from the final new-line requirement, why do you think it

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Guest
Posts: n/a

 03-20-2006
Jack Klein opined:

> On Mon, 20 Mar 2006 02:04:26 +0100, "John F" <spam@127.0.0.1> wrote
> in comp.lang.c:
>
>> > (E-Mail Removed) opined:
>> >
>> >> FordFulkerson.c:117:2: warning: no newline at end of file
>> >
>> > I don't the rational for this requirement.

>>
>> I suppose the standard requires a source file to be a text file
>> (which seems to make some sense).
>>
>> The only formal definition of what a text file is supposed to look
>> like is done by POSIX (AFAIK) and it _requires_ a text file to end
>> with a newline character.

>
> Has nothing at all to do with the POSIX standard, and everything to
> do with the C standard, period:
>
> "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."
>
> The C standard just plain requires that a source file end in a
> new-line character, except for the degenerate case of an empty file.

Thanks for all the info. However, I already knew it's required in the
Standard. I was just wandering about the rationale (I admit messing up
the sentence did not help ). Is it explained in the rationale
document?

--

UNIX enhancements aren't.

=?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
Guest
Posts: n/a

 03-20-2006
Jack Klein wrote:
> On 20 Mar 2006 03:41:01 GMT, Jordan Abel <(E-Mail Removed)> wrote
> in comp.lang.c:
>
> > On 2006-03-20, Jack Klein <(E-Mail Removed)> wrote:
> > > The C standard just plain requires that a source file end in a
> > > new-line character, except for the degenerate case of an empty file.

> >
> > "...which it does not admit at all", I suspect you meant to say. I don't
> > even think a file ending in a newline but containing no declarations is
> > legal.

>
> Let me repost the actual quoted text from the standard, which you
> snipped:
>
> "Each instance of a backslash character (\) immediately followed by a
> new-line character is deleted, splicing physical source lines to form
> logical source lines. Only the last backslash on any physical source
> line shall be eligible for being part of such a splice. 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."
>
> ...since the standard obviously allows for the existence of an empty
> source file, and allows such a source file to be completely empty,
> exempting it from the final new-line requirement, why do you think it

I think you're talking about different things. The grammar does not
permit a translation unit to contain no declarations, but a source file
can legitimately be empty when it is included in another file via
#include.