继续用c语言编写以下代码:int main() { WindowList list = {NULL, NULL}; init_windows(&list, "windows.txt", 3); while (1) { printf("1. 增加窗口\n"); printf("2. 删除窗口\n"); printf("3. 暂停窗口业务\n"); printf("4. 回复窗口业务\n"); printf("5. 保存窗口\n"); printf("6. 退出\n"); printf("输入你的选择:\n "); int choice; scanf("%d", &choice); switch (choice) { case 1: { Window window; printf("
时间: 2024-04-28 12:22:57 浏览: 86
线性链表的创建_插入_删除_操作_C语言.docx
请输入窗口编号:");
scanf("%d", &window.id);
printf("请输入窗口名称:");
scanf("%s", window.name);
printf("请输入窗口业务类型:");
scanf("%s", window.business);
add_window(&list, window);
printf("添加窗口成功!\n");
break;
}
case 2: {
int id;
printf("请输入要删除的窗口编号:");
scanf("%d", &id);
delete_window(&list, id);
printf("删除窗口成功!\n");
break;
}
case 3: {
int id;
printf("请输入要暂停业务的窗口编号:");
scanf("%d", &id);
pause_window(&list, id);
printf("暂停窗口业务成功!\n");
break;
}
case 4: {
int id;
printf("请输入要恢复业务的窗口编号:");
scanf("%d", &id);
resume_window(&list, id);
printf("恢复窗口业务成功!\n");
break;
}
case 5: {
char filename[20];
printf("请输入保存文件名:");
scanf("%s", filename);
save_windows(&list, filename);
printf("保存窗口成功!\n");
break;
}
case 6: {
printf("谢谢使用!\n");
exit(0);
}
default: {
printf("输入有误,请重新输入!\n");
break;
}
}
}
return 0;
}
// 增加窗口
void add_window(WindowList *list, Window window) {
WindowNode *p = (WindowNode*)malloc(sizeof(WindowNode));
p->window = window;
p->next = NULL;
if (list->head == NULL) {
list->head = p;
list->tail = p;
} else {
list->tail->next = p;
list->tail = p;
}
}
// 删除窗口
void delete_window(WindowList *list, int id) {
WindowNode *p = list->head;
WindowNode *prev = NULL;
while (p != NULL) {
if (p->window.id == id) {
if (prev == NULL) {
list->head = p->next;
} else {
prev->next = p->next;
}
free(p);
return;
}
prev = p;
p = p->next;
}
}
// 暂停窗口业务
void pause_window(WindowList *list, int id) {
WindowNode *p = list->head;
while (p != NULL) {
if (p->window.id == id) {
p->window.status = PAUSED;
return;
}
p = p->next;
}
}
// 恢复窗口业务
void resume_window(WindowList *list, int id) {
WindowNode *p = list->head;
while (p != NULL) {
if (p->window.id == id) {
p->window.status = NORMAL;
return;
}
p = p->next;
}
}
// 保存窗口
void save_windows(WindowList *list, char *filename) {
FILE *fp = fopen(filename, "w");
if (fp == NULL) {
printf("无法打开文件!\n");
return;
}
WindowNode *p = list->head;
while (p != NULL) {
fprintf(fp, "%d %s %s %d\n", p->window.id, p->window.name, p->window.business, p->window.status);
p = p->next;
}
fclose(fp);
}
阅读全文