信息管理系统c语言主程序
以下是一个简单的信息管理系统主程序,使用C语言编写:
```c
include <>
include <>
include <>
define MAX_RECORDS 100
define MAX_NAME_LENGTH 50
define MAX_PHONE_LENGTH 20
typedef struct {
    char name[MAX_NAME_LENGTH];
    char phone[MAX_PHONE_LENGTH];
} Record;
Record records[MAX_RECORDS];
int num_records = 0;
void add_record() {
    if (num_records >= MAX_RECORDS) {
        printf("The maximum number of records has been reached.\n");
        return;
    }
    Record new_record;
    printf("Enter the name: ");
    scanf("%s", new_);
    printf("Enter the phone number: ");
    scanf("%s", new_);
    records[num_records++] = new_record;
}
void display_records() {
    printf("Name\tPhone Number\n");
    for (int i = 0; i < num_records; i++) {
        printf("%s\t%s\n", records[i].name, records[i].phone);
    }
}
void search_record() {
    char name[MAX_NAME_LENGTH];
    printf("Enter the name to search for: ");
    scanf("%s", name);
    for (int i = 0; i < num_records; i++) {
        if (strcmp(records[i].name, name) == 0) {
            printf("Phone Number: %s\n", records[i].phone);
            return;
exited        }
    }
    printf("No record found for %s.\n", name);
}
int main() {
    int choice;
    while (1) {
        printf("\nMenu:\n");
        printf("1. Add record\n");
        printf("2. Display records\n");
        printf("3. Search record\n");
        printf("4. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);
        switch (choice) {
            case 1: add_record(); break;
            case 2: display_records(); break;
            case 3: search_record(); break;
            case 4: exit(0); break; // exit(0) will end the program and return status 0, indicating successful completion. If you want to end the program with an error, you can use exit(1). You can also use return instead of exit. For example, return 0 or return 1. The return value is used by the operating system to determine whether the program exited successfully or with an error. The value 0 usually indicates success, and non-zero values indicate errors. In this case, we are using exit(0) to end the program successfully.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。