郁闷:为什么不能赋值?(50分)

  • 主题发起人 visualbird
  • 开始时间
V

visualbird

Unregistered / Unconfirmed
GUEST, unregistred user!
CB5.0中定义一个结构体:
struct SwitcherPorts
{
char UserName[50];
char PassWord[50];
char OtherSettings[100];
};
lstrcpy(SwitcherPorts->UserName,"test11");
SwitcherPorts->UserName始终为空?
 
你的变量呢?
 
strcpy(SwitcherPorts->UserName,"test11");
 
strcpy(SwitcherPorts->UserName,"test11");
结果一样,SwitcherPorts->UserName始终为空
 
SwitcherPorts Tmp;
lstrcpy(Tmp.UserName,"test11");
或者
SwitcherPorts *Tmp = new SwitcherPorts;
lstrcpy(Tmp->UserName,"test11");
 
只定义了类型,没有申明变量,如何赋值
 
zhu_jy 说的好
 
小笨苯的答案基本正确,zhu_jy的解释合情合理。
SwitcherPorts Tmp;
// 完全正确
lstrcpy(Tmp.UserName,"test11");
或者
SwitcherPorts *Tmp = new SwitcherPorts;
if (Tmp != NULL) // BCB中new失败可能会抛出异常(默认),也可能返回NULL,VC中默认返回NULL
lstrcpy(Tmp->UserName,"test11");
 
我怎么看不到答案?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
645
import
I
I
回复
0
查看
575
import
I
I
回复
0
查看
731
import
I
顶部