Я просто столкнулся проблемы таНоса в моем назначении // Это мой файл заголовокMingw использование таНос для структуры
struct vertex_t {
int id;
char *label;
/* A list of vertices representing incoming edges */
List in;
/* A List of vertices representing outgoing edges */
List out;
};
struct graph_t {
/* Number of vertices */
int order;
/* Numb er of edges */
int size;
Vertex vertices;
};
// Нам не разрешено изменять файл заголовок выше. В моем основном файле, как можно malloc вершины в графе?
Graph new_graph(int order) {
Graph graph;
int i;
graph=NULL;
graph=(Graph)malloc(sizeof(Graph));
assert(graph);
graph->order=order;
graph->size=0;
graph->vertices=(Vertex*)malloc((order+100000)*sizeof(Vertex));//!!!!!!!!!!!!!!!!!!!this line!!!!
for(i=0;i<order;i++){
graph->vertices[i].label=(char*)malloc(MAX_LINE_LEN*sizeof(char));
graph->vertices[i].in=NULL;
graph->vertices[i].out=NULL;
}
return graph;
}
Я могу добавить исключительно большое количество в malloc, чтобы предотвратить утечку памяти.
Не ответ, но [не приведите результат 'malloc'] (http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc). например 'graph = (Graph) malloc (sizeof (Graph)); и другие. –
Что такое тип 'Vertex'? –
Где находится 'typedef' для' Vertex' ?? –