Hello, here is my code below... I'm getting compiling errors as below. What is wrong?
Code:
cc1: warnings being treated as errors
q1.c: In function 'GRAPHinit':
q1.c:49: error: implicit declaration of function 'MATRIXint'
q1.c:49: error: assignment makes pointer from integer without a cast
Code:
#include <stdio.h>
#include <stdlib.h>
#define maxV 10
int visited[maxV];
typedef struct { int v; int w; } Edge;
struct graph { int V; int E; int **adj; }; // adj [][] is a matrix.
typedef struct graph *Graph;
Graph GRAPHinit(int V);
int **MATRIXinit(int r, int c, int val);
int GRAPHpath(Graph G, int v, int w);
int pathR(Graph G, int v, int w);
int main(int argc, char *argv[]) {
return 0;
}
int GRAPHpath(Graph G, int v, int w) {
int t;
for (t = 0; t < G -> V; t++) visited[t] = 0;
return pathR(G, v, w);
}
int pathR(Graph G, int v, int w) {
int t;
if (v == w) return 1;
visited[v] = 1;
for (t = 0; t < G ->V; t++)
if (G ->adj[v][t] == 1)
if (visited[t] == 0)
if (pathR(G, t, w)) return 1;
return 0; //We will not come back to v. So, we will leave v as visited.
}
Graph GRAPHinit(int V) {
Graph G = malloc(sizeof *G);
G ->V = V; G->E = 0;
G->adj = MATRIXint(V, V, 0);
return G;
}
int **MATRIXinit(int r, int c, int val){
int i, j;
int **t = malloc( r * sizeof(int *) );
for (i = 0; i < r; i++)
t[i] = malloc(c * sizeof(int));
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
t[i][j] = val;
return t;
}
Thanks