我是C新手,需要創建一個N分支樹,但我無法掌握C的工作方式。在C中創建多分支樹C
到目前爲止,我有這樣的:
#include <stdio.h>
#include <string.h>
typedef struct node {
char name[50];
char type[50]; // There are two kinds of files: directory and archive
int number_archives;
struct nodo *next;
struct nodo *son;
}NODE;
void create_Archive (NODO *ptr,char name[50]){ // ptr points to the node where I'll add the son
NODE new_Node = {name,"Archive",0,NULL,NULL};
ptr->son = &new_Node;
}
當我嘗試編譯我得到這些警告
filetree.c:15:3: warning: initialization makes integer from pointer without a cast [enabled by default]
NODE new_node = {name,"Archive",0,NULL,NULL};
filetree.c:15:3: warning: (near initialization for ‘new_node.name[0]’) [enabled by default]
filetree.c:15:3: warning: initialization makes integer from pointer without a cast [enabled by default]
filetree.c:15:3: warning: (near initialization for ‘new_node.name[1]’) [enabled by default]
filetree.c:15:3: warning: initialization makes integer from pointer without a cast [enabled by default]
如何使程序命名歸檔它在參數給出的同樣的方式的程序?
說我總是遇到另一個錯誤是,當我嘗試使用功能malloc
, 例如:
number = (int*)malloc(sizeof(int));
我得到警告:
filetree.c:18:21: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]
number = (int*) malloc (sizeof(int));
首先得到一個新的鍵盤或學會校對。其次,您需要了解一個值和一個指向某個值的指針之間的差異,這就是所有錯誤的來源。 – stark 2014-09-21 00:44:40