用C语言写一个家谱处理的程序
时间: 2023-02-13 18:27:42 浏览: 155
好的,我来帮助你写一个 C 语言的家谱处理程序。首先,我们需要考虑家谱信息存储的结构。
家谱信息可以用一个结构体来表示,比如这样:
```
struct Family {
char name[30];
char father[30];
char mother[30];
char spouse[30];
int age;
char children[10][30];
};
```
然后我们可以定义一个全局变量,用来存储家谱信息。
```
struct Family family[100];
int family_count = 0;
```
接下来,我们可以写一些函数来处理家谱信息。
例如,我们可以写一个函数来添加家谱信息:
```
void add_family(char *name, char *father, char *mother, char *spouse, int age, char children[][30], int children_count) {
strcpy(family[family_count].name, name);
strcpy(family[family_count].father, father);
strcpy(family[family_count].mother, mother);
strcpy(family[family_count].spouse, spouse);
family[family_count].age = age;
for (int i = 0; i < children_count; i++) {
strcpy(family[family_count].children[i], children[i]);
}
family_count++;
}
```
同样的,我们也可以写一个函数来查找家谱信息:
```
struct Family find_family(char *name) {
for (int i = 0; i < family_count; i++) {
if (strcmp(family[i].name, name) == 0) {
return family[i];
}
}
}
```
我们还可以写一个函数来输出家谱信息:
```
void print_family(char *name) {
struct Family f = find_family(name);
printf("姓名: %s\n", f.name);
printf("父亲: %s\n", f.father);
printf("母亲:
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)