请你定义一个描述学生基本信息的结构,包括姓名,学号,籍贯,身份证号,年龄,家庭住址,性别,联系方式等。编程:
a) 输入基本信息(3~5条记录);
b) 检索一个指定的学生信息,并打印到屏幕上;
c) 输出全体纪录信息;
d) 说明,访问结构的时候,什么时候应该用运算符“.”,什么时候应该用运算符“->”。
请大牛在visual c++ 6.0环境下调试,请做出来一定回复啊!谢大牛了!
以下是程序,不过我用的是visual c++ 2010
#include<stdio.h>
#include<string.h>
#define MAXL 200 /*字符串最大长度*/
#define MAXN 200 /*最多人数*/
typedef struct{
char name[MAXL],native_place[MAXL],address[MAXL],contact_inf[MAXL]; /*姓名,籍贯,住址,联系方式*/
unsigned long long ID_card_number; /*身份证号 vc6可能要把类型改成unsigned __int64 ,下面的%llu可能要改成%I64u*/
int number,age,sex; /*学号,年龄,性别:0男1女 */
}data;
data datas[MAXN];
int main(){
char ch,namef[MAXL];
int count=0,i,found,fi;
do{
printf("please input:a-add data,f-find data,p-print all datas,e-exit\n"); /*a-输入 f-查找 p-输出 e-退出 */
ch=(char)getchar();
if (ch=='a'){
printf("please input:name number native_place ID_card_number age address sex(0:male/1:female) contact_information\n");
scanf("%s %d %s %llu %d %s %d %s",datas[count].name,&datas[count].number,datas[count].native_place,&datas[count].ID_card_number,&datas[count].age,datas[count].address,&datas[count].sex,datas[count].contact_inf);
count++;
}
if (ch=='f'){
printf("please input name\n");
scanf("%s",namef);
found=0;
for(i=0;i<count;i++){
if(!strcmp(datas[i].name,namef)){
found=1;
fi=i;
}
}
if(found){
printf("---result---\nname number native_place ID_card_number age address sex(0:male/1:female) contact_information\n");
printf("%s %d %s %llu %d %s %d %s\n---result---\n",datas[fi].name,datas[fi].number,datas[fi].native_place,datas[fi].ID_card_number,datas[fi].age,datas[fi].address,datas[fi].sex,datas[fi].contact_inf);
}else{
printf("---result---\nnot found!\n---result---\n");
}
}
if(ch=='p'){
if(count){
printf("---result---\nname number native_place ID_card_number age address sex(0:male/1:female) contact_information\n");
for(i=0;i<count;i++){
printf("%s %d %s %llu %d %s %d %s\n",datas[i].name,datas[i].number,datas[i].native_place,datas[i].ID_card_number,datas[i].age,datas[i].address,datas[i].sex,datas[i].contact_inf);
}
printf("---result---\n");
}else{
printf("---result---\nno data---result---\n");
}
}
}while(ch!='e');
return 0;
}
关于第四个问题:
.用于访问该结构体的域
->用于访问该指针指向的结构体的域
StructurePointer->Field 相当于 (*StructurePointer).Field