数据结构中的C语言。 我定义了一个结构体MHNode,其中有一项是char data; 然后在主函数中,
我定义了一个结构体数组MHNodeh[maxsize],当我要给chardata赋值的时候,有问题了,我要赋值的对象是一些单词,长短不一,比如h[0].data=“the...
我定义了一个结构体数组MHNode h[maxsize],当我要给char data 赋值的时候,有问题了,我要赋值的对象是一些单词,长短不一,比如 h[0].data=“the";这样是错的呢,然后我该怎么解决呢?
#include "stdio.h"
#include"string.h"
#include"stdlib.h"
#define maxsize 20
typedef struct
{
char cd[maxsize];
int start;
}HCode;
typedef struct
{
char data;
double weight;
int parent;
int lchild;
int rchild;
}HTNode;
void main()
{
HTNode ht[maxsize];
HCode hcd[maxsize];
strcpy( ht[0].data ,'The');
ht[1].data ='of';
ht[2].data ='a';
ht[3].data ='to';
ht[4].data ='and';
ht[5].data ='in';
ht[6].data ='that';
ht[7].data ='he';
ht[8].data ='is';
ht[9].data ='at';
ht[10].data ='on';
ht[11].data ='for';
ht[12].data ='His';
ht[13].data ='are';
ht[14].data ='be';
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
warning C4305: '=' : truncation from 'const int' to 'char' 展开
#include "stdio.h"
#include"string.h"
#include"stdlib.h"
#define maxsize 20
typedef struct
{
char cd[maxsize];
int start;
}HCode;
typedef struct
{
char data;
double weight;
int parent;
int lchild;
int rchild;
}HTNode;
void main()
{
HTNode ht[maxsize];
HCode hcd[maxsize];
strcpy( ht[0].data ,'The');
ht[1].data ='of';
ht[2].data ='a';
ht[3].data ='to';
ht[4].data ='and';
ht[5].data ='in';
ht[6].data ='that';
ht[7].data ='he';
ht[8].data ='is';
ht[9].data ='at';
ht[10].data ='on';
ht[11].data ='for';
ht[12].data ='His';
ht[13].data ='are';
ht[14].data ='be';
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
warning C4305: '=' : truncation from 'const int' to 'char' 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询