我是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