typedef struct node{
char file[11];
struct node* left;
struct node* right;
};
在主函数中已经定义了一个struct node Node[10001]以及char 类型的pre1
scanf("%s",pre1);
strcpy(Node[j].left->file,pre1);
这样不行,求正解
typedef struct node{
char file[11];
struct node* left;
struct node* right;
};
在主函数中已经定义了一个struct node Node[10001]以及char 类型的pre1
scanf("%s",pre1);
strcpy(Node[j].left->file,pre1);
这样不行,求正解
上述代码中的node[j].left->file是一个结构体指针,这个指针没有指向任何地方,对这个指针进行赋值是不合法的。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node{
char file[11];
struct node* left;
struct node* right;
}Node;
int main()
{
Node* root = (Node*)malloc(sizeof(Node));
root->left = (Node*)malloc(sizeof(Node));
root->right = (Node*)malloc(sizeof(Node));
char pre1[11];
scanf("%s",pre1);
strcpy(root->left->file,pre1);
return 0;
}