c语言数据结构求串长函数
#include
#include
#include
#include
typedef struct{
char *ch;
int length;
}BBT;
int StrAssign(BBT *T,char *chars){
int i ;
char *c;
for(i=0,c=chars;*c;i++,c++);
if(!i){
T.ch=NULL;
T.length=0;
}
else{
if(!(T.ch=(char*)malloc(i*sizeof(char)))){
return -1;
}
for(int n=0;n<=i-1;n++)
T->ch[n] = chars[n];
T->ch[i] = 0;
T->length =i;
}
return 0;
}
int StrLength(BBT S){
return S.length;
}
[Error] request for member 'ch' in 'T', which is of pointer type 'BBT*' (maybe you meant to use '->' ?)
[Error] request for member 'length' in 'T', which is of pointer type 'BBT*' (maybe you meant to use '->' ?)
[Error] request for member 'ch' in 'T', which is of pointer type 'BBT*' (maybe you meant to use '->' ?)
求遇见这个是什么意思,我之前的bbt已经定义了啊
把下面这段代码
typedef struct{
char *ch;
int length;
}BBT;
改为:
typedef struct _BBT{
char *ch;
int length;
} BBT;