|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//按种类查找
void SeekByType(struct address *head)
{
char type[20];
struct address *p=head;
printf("请输入要查找类型\n");
getchar();
gets(type);
printf("ID\tName\tPhone\t\tType\tE-mail\n");
printf("type:A:办公类,B:个人类,C:商务类\n");
while(p!=NULL)
{
if(strcmp(type,p->type)==0)
{
printf("%d\t%s\t%s\t%s\t%s\n",p->num,p->name,p->phone,p->type,p->email);
}
p=p->next;
}
printf("请输入任意键返回\n");
getch();
}
请问为什么要在一开始写char type[20];??希望有大佬求解。
你好,
这是为了有足够内存空间存放数据而定义的。
首先,在32位系统中,1个字符(char)为4字节,64位中,1个char为8字节。
所以先定义type有20个字节(byte),是为了即便在64位中,也能存在2个字符(char)
你可以尝试使用sizeof()运算符,计算 sizeof(type)和sizeof('a'),可能帮助你理解。
|
|