this is prog in C (adjacency.c) that checks if exists in directed graph way from node a to node b
这是在C(邻接。C)中的prog,它检查从节点a到节点b的有向图中是否存在。
# include <stdio.h>
# include <stdlib.h>
#define N 11
#define FALSE 0
#define TRUE 1
typedef int[N][N] adj_mat;
int path (adj_mat A, int u, int v)
void main()
{
adj_mat Matrix;
int dadnode, sonnode;
printf("bla-bla-bla enter nodes.\n");
printf("Press Ctrl+Z after finishing of bla-bla-bla all the nodes\n");
do {
printf("Enter the number of first node\n");
scanf("%d", &dadnode);
printf("Enter the number of second node\n");
scanf("%d", &sonnode;);
if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0))
Matrix[dadnode][sonnode] = 1;
} while ( (dadnode != EOF ) && (sonnode != EOF));
printf("Now enter u and v nodes to check if exists way from u node to we node\n")
printf("Enter the number of u node\n");
scanf("%d", &dadnode);
printf("Enter the number of v node\n");
scanf("%d", &sonnode;);
if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0))
{
if(path(Matrix,dadnode,sonnode) == TRUE )
printf ("Exists way from node u to node v ");
}
else printf printf ("Not exists way from node u to node v ");
}
int path (adj_mat A, int u, int v)
{
if (v >= u)
return FALSE;
int nodenum;
for(nodenum = v - 1; nodenum > 0; nodenum-- )
{
if (A[nodenum][v] == TRUE)
{
if (nodenum == u) /
return TRUE;
else if (path (adj_mat A, int u, int nodenum))
return TRUE;
}
}
return FALSE;
}
when i type command
当我输入命令
gcc -o adjacency -ansi adjacency.c
邻接-ansi邻接。
i get
我得到
adjacency.c:8: error: expected identifier or ‘(’ before ‘[’ token
邻接。c:8:错误:期望标识符或'('之前')。
adjacency.c:10: error: expected ‘)’ before ‘A’
邻接。c:10:错误:在A之前
adjacency.c:58: error: expected ‘)’ before ‘A’
邻接。c:58:错误:预期')在A之前
how to fix ?
如何修复?
update: thanks to all for help. compiled.
更新:感谢所有人的帮助。编译。
4 个解决方案
#1
9
You should move the [N][N]
part to the end of the declaration, and add a semicolon after the forward declaration of path
.
您应该将[N][N]部分移到声明的末尾,并在前面的路径声明之后添加一个分号。
typedef int adj_mat[N][N];
int path (adj_mat A, int u, int v);
There are also inaccuracies in the remaining of your code:
代码的剩余部分也有不准确之处:
-
scanf("%d", &sonnode;);
has extra semicolon, should bescanf("%d", &sonnode);
- scanf(“% d”,&sonnode;);有额外的分号,应该是scanf(“%d”,&sonnode);
-
else printf printf
should beelse printf
- 其他printf printf也应该是printf。
- Semicolons are missing in a few places
- 在一些地方分号不见了。
- a
/
is at the end of one line that shouldn't be there - a在一行的末尾,不应该在那里。
-
main
needs to return anint
- 主要需要返回一个整数。
#2
4
The type int[N][N]
is not valid C++. Try:
类型int[N][N]不是有效的c++。试一试:
typedef int adj_mat[N][N];
instead.
代替。
Also:
另外:
You need a semicolon (';
') at the end of lines:
在行末尾需要一个分号(';'):
int path (adj_mat A, int u, int v)
printf("Now enter u and v nodes to check if exists way from u node to we node\n")
You do not need the first semicolon in
您不需要第一个分号。
scanf("%d", &sonnode;);
You have an extra (superfluous) printf in
你有多余的(多余的)printf。
else printf printf ("Not exists way from node u to node v ");
You have an invalid line in
你有一条无效的线。
if (nodenum == u) /
#3
1
You're missing the semicolon after the function definition on line 10:
在第10行函数定义之后,你会丢失分号:
int path (adj_mat A, int u, int v);
#4
1
There's a semicolon missing at the end of below line.
在下面一行的末尾有一个分号。
int path (adj_mat A, int u, int v);
#1
9
You should move the [N][N]
part to the end of the declaration, and add a semicolon after the forward declaration of path
.
您应该将[N][N]部分移到声明的末尾,并在前面的路径声明之后添加一个分号。
typedef int adj_mat[N][N];
int path (adj_mat A, int u, int v);
There are also inaccuracies in the remaining of your code:
代码的剩余部分也有不准确之处:
-
scanf("%d", &sonnode;);
has extra semicolon, should bescanf("%d", &sonnode);
- scanf(“% d”,&sonnode;);有额外的分号,应该是scanf(“%d”,&sonnode);
-
else printf printf
should beelse printf
- 其他printf printf也应该是printf。
- Semicolons are missing in a few places
- 在一些地方分号不见了。
- a
/
is at the end of one line that shouldn't be there - a在一行的末尾,不应该在那里。
-
main
needs to return anint
- 主要需要返回一个整数。
#2
4
The type int[N][N]
is not valid C++. Try:
类型int[N][N]不是有效的c++。试一试:
typedef int adj_mat[N][N];
instead.
代替。
Also:
另外:
You need a semicolon (';
') at the end of lines:
在行末尾需要一个分号(';'):
int path (adj_mat A, int u, int v)
printf("Now enter u and v nodes to check if exists way from u node to we node\n")
You do not need the first semicolon in
您不需要第一个分号。
scanf("%d", &sonnode;);
You have an extra (superfluous) printf in
你有多余的(多余的)printf。
else printf printf ("Not exists way from node u to node v ");
You have an invalid line in
你有一条无效的线。
if (nodenum == u) /
#3
1
You're missing the semicolon after the function definition on line 10:
在第10行函数定义之后,你会丢失分号:
int path (adj_mat A, int u, int v);
#4
1
There's a semicolon missing at the end of below line.
在下面一行的末尾有一个分号。
int path (adj_mat A, int u, int v);