#include<stdio.h> #define N 2 void intput(int *); void output(); void change(); void select(); struct people { int bno[N],phone[N];//编号,电话号码 char name[N],email[N],address[N],pet[N];//名字,邮箱,家庭地址,昵称 }people[N]; struct people person[20]; int main() { int a=0,b,sum=0; while(a==0) { printf("------欢迎来到通讯录系统!----------\n"); printf("输入“1”添加联系人,输入“2”删除联系人,输入“3”更改联系人,"); printf(" 输入“4”显示已有联系人,输入“5”退出系统。\n"); scanf("%d",&b); if(b==1) { intput(&sum); } if(b==2) { } if(b==3) { } return 0; } void intput(int *sum) { int i; for(i=0;i<N;i++) { printf("\n请分别输入姓名、昵称、电话号码、邮箱、家庭地址(用英文逗号隔开):\n"); scanf("%s %s %d %s %s",&person[i].name,person[i].pet,person[i].phone,person[i].email,person[i].address); } }
时间: 2023-06-27 15:02:01 浏览: 35
这段代码是一个简单的通讯录系统,包含添加联系人、删除联系人、更改联系人和显示已有联系人等功能。其中,使用了结构体来存储每个联系人的信息,包括编号、姓名、昵称、电话号码、邮箱和家庭地址等。
在主函数中,使用了一个while循环来不断接收用户输入的操作选项,根据不同的选项调用不同的函数来完成相应的功能。其中,intput函数用于添加联系人,它使用了指针来记录已有联系人的数量,每次添加联系人时将其信息存储到person结构体数组中,并将已有联系人数量加1。
需要注意的是,这段代码中存在一些问题,比如删除联系人、更改联系人等功能并未实现,而且数据存储方式也不太合理。如果你想进一步完善这个通讯录系统,可以考虑使用链表来存储联系人信息,同时完善删除联系人、更改联系人等功能的实现。
相关问题
#include<stdio.h> void main(){}
`#include<stdio.h>` 是C语言中预处理指令,用于包含标准输入输出库(stdio.h),提供了基本的输入输出功能,如 printf 和 scanf。`void main()` 是程序的主入口点,在C语言中,所有的C程序都必须从这里开始执行。`{}` 包围的内容是main函数中的代码块。
当您看到这样的代码:
```c
#include<stdio.h>
void main() {}
```
这表示:
1. 首先,程序包含了stdio库,使其能够使用标准输入输出操作。
2. 然后,定义了一个名为 `main` 的函数,这是程序执行的起点。函数类型为 `void`,意味着它不返回任何值。`main` 后面紧跟着一对空括号 `{}` 表示这个函数没有实际的操作,只是声明它的存在。
#include<stdio.h> #include<stdlib.h>
#include<stdio.h>和#include<stdlib.h>是C语言中的预处理指令,用于引入标准输入输出函数和动态内存分配函数。它们通常一起使用,但有时候会出现报错的情况。
报错的原因可能是由于编译器或IDE的设置问题,或者是代码中的其他错误导致的。在某些情况下,删除#include<stdlib.h>可能会解决报错问题,但这并不是一个通用的解决方案。
为了解决这个问题,你可以尝试以下几个步骤:
1. 确保你的编译器或IDE已正确配置,并且能够找到正确的头文件路径。
2. 检查你的代码中是否存在其他错误,例如语法错误、函数声明错误等。
3. 尝试使用不同的编译器或IDE来编译你的代码,看是否能够解决问题。
4. 如果以上步骤都没有解决问题,你可以尝试在代码中手动声明所需的函数,而不使用#include<stdlib.h>。例如,你可以在代码中添加以下声明:
```c
void *malloc(size_t size);
void free(void *ptr);
```
请注意,这只是一种临时解决方案,如果你的代码依赖于stdlib.h中的其他函数或定义,可能会导致其他问题。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)