This example shows how to get graph node by node name and how to query node attributes.
The input file is assumed to be in GraphViz DOT language.
For the graph shown below the program produces the following output:
Node: a, shape: box, color: red
Node: b, shape: hexagon, color: green
Node: c, shape: circle, color: blue

1 #pragma package ".." 2 #include "chagraph.h" 3 #include <stdlib.h> 4 5 int main(int argc, char *argv[]) 6 { 7 Agraph_t *g; 8 Agnode_t *n; 9 10 if (argc < 2) { 11 printf("Usage: %s file\n" 12 " file -- file in GraphViz dot format\n", 13 argv[0]); 14 exit(EXIT_FAILURE); 15 } 16 FILE *f = fopen(argv[1], "r"); 17 g = agread(f, 0); 18 fclose(f); 19 20 char *node_name[] = {"a", "b", "c"}; 21 int i; 22 for (i=0; i<3; i++) { 23 n = agnode(g, node_name[i], FALSE); 24 if (n != 0) { 25 printf("Node: %s, shape: %s, color: %s\n", 26 agnameof(n), 27 agget(n, "shape"), 28 agget(n, "color")); 29 } 30 } 31 32 agclose(g); 33 return 0; 34 }