定义一个editeinfo()函数,功能是修改指定住户的信息。函数声明:void editeinfo(datatype arr[], int index);参数说明:arr为住户信息结构数组,待修改下标index
时间: 2023-06-04 15:07:04 浏览: 41
为要修改的住户在数组中的位置。函数实现如下:
void editeinfo(datatype arr[], int index){
printf("请输入要修改的住户信息:\n");
printf("姓名:");
scanf("%s",arr[index].name);
printf("年龄:");
scanf("%d",&arr[index].age);
printf("性别:");
scanf("%s",arr[index].sex);
printf("身份证号码:");
scanf("%s",arr[index].idcard);
printf("电话号码:");
scanf("%s",arr[index].phone);
printf("电子邮箱:");
scanf("%s",arr[index].email);
printf("修改成功!\n");
}
其中,datatype为住户信息结构体类型,包含name、age、sex、idcard、phone、email等成员变量,可根据实际需要进行修改。
相关问题
定义输出函数void ptn(datatype arr[],int n),功能是输出数组arr中所有住户信息
void ptn(datatype arr[], int n) {
for(int i=0; i<n; i++) {
printf("住户姓名:%s\n", arr[i].name);
printf("住户年龄:%d\n", arr[i].age);
printf("住户性别:%c\n", arr[i].gender);
printf("住户地址:%s\n", arr[i].address);
printf("住户电话:%s\n", arr[i].phone);
}
}
其中,datatype为住户信息的数据类型,包含姓名、年龄、性别、地址、电话等信息。n为数组的长度。
定义输出函数void ptn(datatype arr[],int n),功能是输出数组arr中全部n条住户信息
好的,这个问题属于技术问题,我可以回答。下面是输出函数的代码:
void ptn(datatype arr[], int n) {
for(int i = 0; i < n; i++) {
cout << "住户信息: ";
cout << arr[i].name << " ";
cout << arr[i].age << " ";
cout << arr[i].gender << " ";
cout << arr[i].address << " ";
cout << endl;
}
}
其中,datatype代表存储住户信息的结构体类型,结构体包含name、age、gender、address等成员变量。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)