I am new to C, know some Java. Trying to write a program that accepts 2D array that represents a directed adjacency matrix, and two numbers, scans the array and returns true if there is a directed path between them (top-down).
I am running into a problem with C implementation. Apparently I have to use pointers to values in array, whilst in Java I could've use values from array (compare, return to function, etc).
I'm pretty sure the logic is in place, I just need help with allocating '*'s in the right places and amounts.
Here's the code:
#include <stdio.h>
#define N 12
typedef int bool;
enum {false, true};
typedef struct adj_mat{
int A [N][N];
}adj_mat;
int path(struct adj_mat A, int origin, int dest){
int i;
if (origin == dest) return true;
for (i = 0; i < sizeof(A);i++){
if (A[origin][i]){
return path (A, i, dest);
}
}
return false;
}
Thanks in advance.
sizeof Adoesn't do what you think it does. Google it.sizeof A / sizeof *Ato get number of elements ofA.