请问如何用GDB输出结构体中的内容?
比如有以下的程序#include<stdio.h>#include<string.h>#include<stdlib.h>typedefstructnode*link;s...
比如有以下的程序
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node *link;
struct node {
int v;
int len;
link next;
};
typedef struct graph *Graph;
struct graph {
int V;
int E;
link *adj;
};
typedef struct edge Edge;
struct edge {
int v;
int w;
int len;
};
Graph graph_init(int v)
{
int i;
Graph t = malloc(sizeof *t);
t->V = v;
t->E = 0;
t->adj = malloc(sizeof(v * sizeof(link)));
for (i = 0; i < v; i++) {
t->adj[i] = NULL;
}
return t;
}
link NEW(int v, link next, int len)
{
link t = malloc(sizeof *t);
t->v = v;
t->next = next;
t->len = len;
return t;
}
Edge EDGE(int v, int w, int len)
{
Edge tmp;
tmp.v = v;
tmp.w = w;
tmp.len = len;
return tmp;
}
void graph_insert(Graph G, Edge e)
{
int v = e.v;
int w = e.w;
int len = e.len;
G->adj[v] = NEW(w, G->adj[v], len);
G->adj[w] = NEW(v, G->adj[w], len);
G->E++;
}
void graph_print(Graph G)
{
int i;
link tmp;
for (i = 0; i < G->V; i++) {
printf("%d:", i);
for (tmp = G->adj[i]; tmp->next != NULL; tmp = tmp->next) {
printf("%d %d\t", tmp->v, tmp->len);
}
printf("\n");
}
}
int main(void)
{
Graph G;
int i;
int v, w, len;
G = graph_init(5);
for (i = 0; i < 5; i++) {
scanf("%d%d%d", &v, &w, &len);
graph_insert(G, EDGE(v, w, len));
}
graph_print(G);
return 0;
}
我想在用GDB调试的时候观察整个G中的内容,就是怎样用GDB查看连续链表中的内容? 展开
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node *link;
struct node {
int v;
int len;
link next;
};
typedef struct graph *Graph;
struct graph {
int V;
int E;
link *adj;
};
typedef struct edge Edge;
struct edge {
int v;
int w;
int len;
};
Graph graph_init(int v)
{
int i;
Graph t = malloc(sizeof *t);
t->V = v;
t->E = 0;
t->adj = malloc(sizeof(v * sizeof(link)));
for (i = 0; i < v; i++) {
t->adj[i] = NULL;
}
return t;
}
link NEW(int v, link next, int len)
{
link t = malloc(sizeof *t);
t->v = v;
t->next = next;
t->len = len;
return t;
}
Edge EDGE(int v, int w, int len)
{
Edge tmp;
tmp.v = v;
tmp.w = w;
tmp.len = len;
return tmp;
}
void graph_insert(Graph G, Edge e)
{
int v = e.v;
int w = e.w;
int len = e.len;
G->adj[v] = NEW(w, G->adj[v], len);
G->adj[w] = NEW(v, G->adj[w], len);
G->E++;
}
void graph_print(Graph G)
{
int i;
link tmp;
for (i = 0; i < G->V; i++) {
printf("%d:", i);
for (tmp = G->adj[i]; tmp->next != NULL; tmp = tmp->next) {
printf("%d %d\t", tmp->v, tmp->len);
}
printf("\n");
}
}
int main(void)
{
Graph G;
int i;
int v, w, len;
G = graph_init(5);
for (i = 0; i < 5; i++) {
scanf("%d%d%d", &v, &w, &len);
graph_insert(G, EDGE(v, w, len));
}
graph_print(G);
return 0;
}
我想在用GDB调试的时候观察整个G中的内容,就是怎样用GDB查看连续链表中的内容? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询