#include <stdio.h> #include <string.h> #include <conio.h> #include <stdlib.h> #include <windows.h>
时间: 2023-09-14 19:04:33 浏览: 66
这是一段 C 语言代码的头文件部分,包含了一些常用的标准库和系统库,如stdio.h、string.h、conio.h、stdlib.h 和 windows.h。其中,stdio.h 提供了标准输入输出函数,如printf、scanf 等;string.h 提供了字符串操作函数,如strcpy、strcat、strlen 等;conio.h 提供了控制台输入输出函数,如getch、putch 等;stdlib.h 提供了一些通用工具函数,如malloc、free、rand 等;windows.h 则提供了一些操作系统相关的函数和数据类型。
相关问题
#include <stdio.h> #include <string.h> #include <conio.h> #include <stdlib.h>4 typedef struct book_info { //定义图书信息的结构体变量并声明新的类型名 char loginNo[10]; /*登录号*/ char name[20]; /*书名*/ char author[20]; /*作者名*/ char classNo[10]; /*分类名*/ char company[20]; /*出版单位*/ char date[20]; /*出版日期*/ char price[10]; /*价格*/ struct book_info *next; }Booklist, *Pointer; int num = 0; //全局变量的定义 Pointer Head = NULL; //头指针为空 FILE *fp; //指向文件的指针
这段代码定义了一个结构体变量 `book_info`,用于存储图书信息。其中,结构体包含了图书的登录号、书名、作者名、分类名、出版单位、出版日期和价格等信息,同时还定义了一个指向下一个结构体变量的指针 `next`。此外,代码还定义了三个全局变量:`num` 表示图书数量,`Head` 表示链表的头指针,初始值为空,`fp` 为指向文件的指针。
需要注意的是,此代码中包含了多个头文件,分别是 `<stdio.h>`、`<string.h>`、`<conio.h>` 和 `<stdlib.h>`。其中,`<stdio.h>` 是 C 语言标准库中的头文件,用于提供输入输出函数;`<string.h>` 提供了字符串处理函数;`<conio.h>` 提供了控制台输入输出函数;`<stdlib.h>` 提供了一些通用工具函数,如动态内存分配函数等。
此外,代码中还定义了一个新类型名 `Booklist`,用来代替 `struct book_info`,方便代码编写。同时,还定义了一个指向 `Booklist` 的指针 `Pointer`,用于遍历链表。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include "添加药品.cpp" struct medicine { char name[20]; char number[50]; char price[50]; char type[10]; char inventory[50]; char brand[20]; char time[60]; char remark[30]; }medicines[100]; int num; int main(void) { int selectnum;add_medicine(); }int add_medicine() { printf("输入要保存的药品信息\n"); printf("输入药品名称\n"); scanf("%s",medicines[num].name); printf("输入药品编号\n"); scanf("%s",medicines[num].number); printf("输入药品单价\n"); return 0; } 帮我将这串代码分成两个cpp文件,一个主文件,一个子文件
主文件(main.cpp):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "medicine.h"
struct medicine medicines[100];
int num;
int main(void) {
int selectnum;
add_medicine();
return 0;
}
子文件(medicine.cpp):
#include "medicine.h"
#include <stdio.h>
int add_medicine() {
printf("输入要保存的药品信息\n");
printf("输入药品名称\n");
scanf("%s",medicines[num].name);
printf("输入药品编号\n");
scanf("%s",medicines[num].number);
printf("输入药品单价\n");
return 0;
}
头文件(medicine.h):
#ifndef MEDICINE_H
#define MEDICINE_H
struct medicine {
char name[20];
char number[50];
char price[50];
char type[10];
char inventory[50];
char brand[20];
char time[60];
char remark[30];
};
int add_medicine();
#endif