麻烦的错误 [英] Pesky Error

查看:76
本文介绍了麻烦的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我弄清楚为什么会出现这个错误感谢

的帮助。


错误:

cc FordFulkerson.c

FordFulkerson.c:117:2:警告:文件末尾没有换行


代码:

#包括< stdio.h>

#define白色0

#define灰色1

#define黑色2

#define MAX_NODES 1000

#define oo 1000000000

//声明

int n; //节点数

int e; //边数

int capacity [MAX_NODES] [MAX_NODES]; //容量矩阵

int flow [MAX_NODES] [MAX_NODES]; // flow matrix

int color [MAX_NODES]; //广度优先搜索需要

int pred [MAX_NODES]; //用于存储扩充路径的数组

int min(int x,int y){

返回x< y? x:y; //返回最小值x和y

}


//广度优先搜索队列

int head,tail ;

int q [MAX_NODES + 2];


void enqueue(int x){

q [tail] = x;

tail ++;

color [x] = GREY;

}


int dequeue() {

int x = q [head];

head ++;

color [x] = BLACK;

返回x;

}


//广度优先搜索扩充路径

int bfs(int start,int target ){

int u,v;

for(u = 0; u< n; u ++){

color [u] = WHITE ;

}

head = tail = 0;

enqueue(start);

pred [start] = -1;

while(head!= tail){

u = dequeue();

//搜索所有相邻的白色节点v。如果容量

//从剩余网络中的u到v是正的,

// enqueue v。

for(v = 0; v< n; v ++){

if(color [v] == WHITE&&am磷; capacity [u] [v] -flow [u] [v]> 0){

enqueue(v);

pred [v] = u;

}

}

}

//如果目标节点的颜色现在为黑色,

//这意味着我们达到了它。

返回颜色[目标] ==黑色;

}


// Ford-Fulkerson算法

int max_flow(int source,int sink){

int i,j,u;

//初始化空流量。

int max_flow = 0;

for(i = 0; i< n; i ++){

for(j = 0; j< n; j ++){

flow [i] [j] = 0;

}

}

//当存在扩充路径时,

//沿着这条路径增加流量。

while(bfs(source,sink)){

//确定我们可以增加流量的数量。

int increment = oo;

for(u = n-1; pred [u ]> = 0; u = pred [u]){

增量= min(增量,容量[pred [u]] [u] -flow [pred [u]] [u]) ;

}

//现在增加f (。= u-n-1;
; PRED [U]> = 0; u = pred [u]){

flow [pred [u]] [u] + =增量;

flow [u] [pred [u]] - =增量;

}

max_flow + =增量;

}

//不再增加路径。我们完成了。

返回max_flow;

}


//读取输入文件和主程序

void read_input_file(){

int a,b,c,i,j;

FILE * input = fopen(" mf.in"," ; r");

//读取节点数和边数

fscanf(输入,%d%d,& n,& e);

//初始化空容量矩阵

for(i = 0; i< n; i ++){

for(j = 0; j< ; n; j ++){

容量[i] [j] = 0;

}

}

//读边缘容量

for(i = 0; i< e; i ++){

fscanf(输入,'%d%d%d',& a,& b,& c);

容量[a] [b] = c;

}

fclose(输入) ;

}


int main(){

read_input_file();

printf(" ;%d \ n",max_flow(0,n-1));

返回0;

}


再次感谢您的帮助。

解决方案

al**********@yahoo.com 认为:

有人可以帮我弄清楚为什么会出现这个错误感谢
求助。

错误:
cc FordFulkerson.c FordFulkerson.c:117:2:警告:文件末尾没有换行符




正是出于错误文本中给出的原因。
编译器期望换行符是源

文件中的最后一行。只需转到文件的最后,点击< ENTER>,然后它就会消失。


我不理解这个要求。当从Usenet文章中复制/粘贴代码时,我也倾向于看到很多

。 :-(


<剪掉很多代码,最后没有换行符>


-

BR,弗拉基米尔


我们应该有一个Vollyballocracy。我们选出六包总统。

每个人都服用直到他们搞砸了,此时他们轮换了。

- Dennis Miller


albert_re ... @ yahoo.com写道:

有人可以帮我弄清楚为什么会出现这个错误感谢
求助。

错误:
cc FordFulkerson.c
FordFulkerson.c:117: 2:警告:文件末尾没有换行符




[剪掉超过100行代码]


你错过了在源文件的末尾需要换行符,

但是我看到你可能会因为过于神秘的错误而感到困惑

消息......

Robert Gamble


Robert Gamble写道:

albert_ re ... @ yahoo.com写道:

有人可以帮我弄清楚为什么会出现这个错误感谢
求助。

错误:
cc FordFulkerson.c
FordFulkerson.c:117:2:警告:文件末尾没有换行符



[剪掉超过100行代码]

您在源文件末尾缺少必需的换行符,
但是我看到您可能会对过于神秘的错误消息感到困惑
消息......


嗯,对于初学者来说,什么是换行符,是吗?是否与新行相同?

当我添加换行符时,我实际上并没有看到新行,请注意。

当然,当您跨平台移动源文件时,您可能需要使用新换行符来



并且不要让我开始关于文件结束......


S.


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
}

//A Queue for Breadth-First Search
int head,tail;
int q[MAX_NODES+2];

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

int dequeue () {
int x = q[head];
head++;
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;
}
head = tail = 0;
enqueue(start);
pred[start] = -1;
while (head!=tail) {
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
void read_input_file() {
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;
}
}
// read edge capacities
for (i=0; i<e; i++) {
fscanf(input,"%d %d %d",&a,&b,&c);
capacity[a][b] = c;
}
fclose(input);
}

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

Again thanks for the help.

解决方案

al**********@yahoo.com 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>

--
BR, Vladimir

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


albert_re...@yahoo.com 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


Robert Gamble wrote:

albert_re...@yahoo.com 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.


这篇关于麻烦的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆