printf(" 请输入你要查找的哪一个班费信息:"); printf(" 如:编号 收支 经办人 原因 金额 人数 日期 \n"); char variable[30], temp_find[20]; scanf("%s", variable); if (strcmp(variable, "编号") && strcmp(variable, "经办人") && strcmp(variable, "原因") && strcmp(variable, "部门") && strcmp(variable, "金额") && strcmp(variable, "时间") ) { printf(" 输入 %s 有误\n", variable); break; } printf(" 请输入要查找的元素"); scanf("%s", temp_find); if (SearchList(L, variable, temp_find)) printf(" 查找成功\n"); else printf(" 您所要查找的信息不存在\n"); break;
时间: 2024-04-25 08:27:27 浏览: 11
这段代码是一个查找函数的实现。它首先要求用户输入要查找的班费信息的字段,如:"编号"、"经办人"、"原因"、"部门"、"金额"、"时间"。然后判断用户输入的字段是否正确,如果不正确则输出提示信息并结束函数。如果用户输入的字段正确,就继续要求用户输入要查找的元素。然后调用SearchList函数进行查找,如果查找成功则输出"查找成功",否则输出"您所要查找的信息不存在"。
注意,strcmp函数返回值为0时表示两个字符串相等,所以条件语句中应该使用!来判断是否不相等。
相关问题
用C语言编写班费收支管理系统代码有1.输入班费收支编号,日期和详细信息。2.输入要删改的信息编号进行信息的删改,3.输入编号查询收支信息,4.展示所有的班费收支信息,并计算余额,5.退出系统。
以下是一个简单的班费收支管理系统的C语言代码示例,其中包括了输入、查询、修改、删除、展示和退出功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RECORDS 100 // 最大记录数目
struct Record {
int id; // 收支编号
char date[20]; // 日期
char detail[50]; // 详细信息
int amount; // 收支金额
};
struct Record records[MAX_RECORDS]; // 记录数组
int num_records = 0; // 记录数目
// 显示菜单
void display_menu() {
printf("\n班费收支管理系统\n");
printf("1. 输入班费收支\n");
printf("2. 修改班费收支\n");
printf("3. 删除班费收支\n");
printf("4. 查询班费收支\n");
printf("5. 展示所有班费收支\n");
printf("6. 退出系统\n");
printf("请选择操作:");
}
// 输入班费收支
void input_record() {
printf("\n请输入班费收支编号、日期、详细信息和金额:\n");
scanf("%d %s %s %d", &records[num_records].id, records[num_records].date, records[num_records].detail, &records[num_records].amount);
num_records++;
printf("记录已添加!\n");
}
// 修改班费收支
void modify_record() {
int id;
printf("\n请输入要修改的班费收支编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
if (records[i].id == id) {
printf("请输入新的日期、详细信息和金额:\n");
scanf("%s %s %d", records[i].date, records[i].detail, &records[i].amount);
printf("记录已修改!\n");
return;
}
}
printf("没有找到该记录!\n");
}
// 删除班费收支
void delete_record() {
int id;
printf("\n请输入要删除的班费收支编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
if (records[i].id == id) {
for (int j = i; j < num_records - 1; j++) {
records[j] = records[j + 1];
}
num_records--;
printf("记录已删除!\n");
return;
}
}
printf("没有找到该记录!\n");
}
// 查询班费收支
void query_record() {
int id;
printf("\n请输入要查询的班费收支编号:");
scanf("%d", &id);
for (int i = 0; i < num_records; i++) {
if (records[i].id == id) {
printf("班费收支编号:%d\n", records[i].id);
printf("日期:%s\n", records[i].date);
printf("详细信息:%s\n", records[i].detail);
printf("金额:%d\n", records[i].amount);
return;
}
}
printf("没有找到该记录!\n");
}
// 展示所有班费收支
void show_records() {
printf("\n所有班费收支记录如下:\n");
int balance = 0;
for (int i = 0; i < num_records; i++) {
printf("班费收支编号:%d\n", records[i].id);
printf("日期:%s\n", records[i].date);
printf("详细信息:%s\n", records[i].detail);
printf("金额:%d\n", records[i].amount);
balance += records[i].amount;
}
printf("当前余额为:%d\n", balance);
}
int main() {
int choice;
do {
display_menu();
scanf("%d", &choice);
switch (choice) {
case 1:
input_record();
break;
case 2:
modify_record();
break;
case 3:
delete_record();
break;
case 4:
query_record();
break;
case 5:
show_records();
break;
case 6:
printf("\n感谢使用班费收支管理系统!\n");
exit(0);
default:
printf("\n无效的选择,请重新选择!\n");
}
} while (1);
return 0;
}
```
这段代码实现了班费收支管理系统的所有功能,包括输入、查询、修改、删除、展示和退出。用户可以根据提示进行相应的操作。其中,所有的记录都存储在一个结构体数组中,每条记录包括班费收支编号、日期、详细信息和金额。在展示所有班费收支时,系统会自动计算当前余额。
int SearchList(struct MyList *L, char variable, char temp_find) { struct MyList *temp = L->next; printf("查找中\n"); while (temp != NULL) { if (!strcmp(variable, "编号")) if (!strcmp(temp->thing.num, temp_find)) { printf(" 班费收支编号为: %s\n", temp->thing.num); printf(" 收入和还是支出: %s\n", temp->thing.into); printf(" 经办人是: %s\n", temp->thing.name); printf(" 收费原因为: %s\n", temp->thing.cause); printf(" 收费金额为: %s\n", temp->thing.money); printf(" 收费的总人数为: %s\n", temp->thing.people); printf(" 收费的日期为: %s\n", temp->thing.time); printf("\n"); }
这段代码定义了一个名为SearchList的函数,其作用是在链表L中查找特定字段为temp_find的节点,并打印该节点的所有数据。具体来说:
- 函数接受三个参数:指向链表头的指针L、要查找的字段名称variable和要查找的字段值temp_find。
- 函数返回值为整型,表示查找到的节点个数。
- 首先定义了一个指针变量temp,指向链表头的下一个节点。
- 执行printf语句,输出"查找中"的提示信息。
- 进入while循环,只要temp不为NULL,就执行循环体中的语句。
- 在循环体中,如果要查找的字段为"编号",且当前节点的编号与要查找的编号相同,则打印该节点的所有数据。
- 最后将temp指向下一个节点,继续遍历,直到temp为NULL,退出循环。
- 返回查找到的节点个数。