C语言其他头文件
点击此处查看C语言所有头文件
🔑 以下内容只做简单介绍,想看详细介绍可进cplusplus网页文档自行查看
✨常用头文件
stdio.h: 标准的输入输出头文件
int sprintf_s( char* const B, size_t const BCount,char const* const _Format,...)
int sscanf_s(char const* const B,char const* const F, ...)
string.h: 字符处理头文件
assert.h: 做断言处理
time.h:时间头文件
- struct tm类型:
struct tm
{
int tm_sec; // seconds after the minute - [0, 60] including leap second
int tm_min; // minutes after the hour - [0, 59]
int tm_hour; // hours since midnight - [0, 23]
int tm_mday; // day of the month - [1, 31]
int tm_mon; // months since January - [0, 11] //月份也是从0开始
int tm_year; // years since 1900 //从1900开始
int tm_wday; // days since Sunday - [0, 6] //星期几:从0开始
int tm_yday; // days since January 1 - [0, 365]
int tm_isdst; // daylight savings time flag
};
- time函数可以获取时间戳
static time_t time(time_t* const _Time)
- ctime: 把时间戳转换为字符串直接打印出来
static char* ctime(const* const _Time)
math.h: 数学函数
double sqrt(_In_ double _X) //开平方根
double pow(_In_ double _X, _In_ double _Y) //2的3次方
int abs(_In_ int _X) //求绝对值
stdbool.h: bool类型
#define bool _Bool
#define false 0
#define true 1
✨其他头文件
errno.h:描述错误代码
fenv.h: 浮点数据的一些设置
float.h:浮点数的一些特征
inttypes.h: 宽整数的描述
iso646.h: 特殊英语单词替换运算符
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
limits.h: 描述数据范围使用
#define MB_LEN_MAX 5
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
#define USHRT_MAX 0xffff
#define INT_MIN (-2147483647 - 1)
#define INT_MAX 2147483647
#define UINT_MAX 0xffffffff
#define LONG_MIN (-2147483647L - 1)
#define LONG_MAX 2147483647L
#define ULONG_MAX 0xffffffffUL
#define LLONG_MAX 9223372036854775807i64
#define LLONG_MIN (-9223372036854775807i64 - 1)
#define ULLONG_MAX 0xffffffffffffffffui64
#define _I8_MIN (-127i8 - 1)
#define _I8_MAX 127i8
#define _UI8_MAX 0xffui8
#define _I16_MIN (-32767i16 - 1)
#define _I16_MAX 32767i16
#define _UI16_MAX 0xffffui16
#define _I32_MIN (-2147483647i32 - 1)
#define _I32_MAX 2147483647i32
#define _UI32_MAX 0xffffffffui32
#define _I64_MIN (-9223372036854775807i64 - 1)
#define _I64_MAX 9223372036854775807i64
#define _UI64_MAX 0xffffffffffffffffui64
locale.h:环境设置
setjmp.h: 跨函数跳转的语句 ---->不建议用
signal.h: 信号量: 做进程的,目前不需要掌握
stdarg.h: 可变参函数: printf函数
stddef.h: 定义一个宏,一般表示类型
#ifdef _WIN64
typedef unsigned __int64 size_t;
typedef __int64 ptrdiff_t;
typedef __int64 intptr_t;
#else
typedef unsigned int size_t;
typedef int ptrdiff_t;
typedef int intptr_t;
#endif
stdint.h: int类型的数据描述
tgmath.h : 数学函数宏
uchar.h: 无符号char类型的一些描述
wchar.h:宽字节版本的字符串处理函数
ctype.h: 数据类型判断的一些头文件
wctype.h: 宽字节版本的数据类型
可变参函数
- 可变参函数实现前加头文件: stdarg.h
- 基础知识
//宏函数
va_list: 保存所有参数
va_start: 参数的第一个位置
va_end: 参数的最后一个位置
va_arg: 参数
... : 参数包:无参或者多个参数,参数的个数不定
int __CRTDECL printf(char const* const _Format,...);
- 简单案例: 求不定参数的数字的和
#include <stdio.h>
#include <stdarg.h>
//count: 有几个参数
//data: 第一个参数
//... 参数包
int Sum(int count, int data, ...)
{
int i, sum = data;
va_list ap; //保存所有参数
va_start(ap, data); //第一个参数的位置是data
for (int i = 1; i < count; i++)
{
//va_arg
sum += va_arg(ap, int);
}
va_end(ap);
return sum;
}
void testSum()
{
printf("%d\n", Sum(3, 1, 2, 3));
printf("%d\n", Sum(5, 1, 2, 3,4,5));
printf("%d\n", Sum(6, 1, 2, 3,4,5,6));
}
//简单实现printf函数
void myprint(const char* str, ...)
{
va_list ap;
int iNum;
double dNum;
va_start(ap, str);
while (*str)
{
if (*str == '%')
{
str++;
switch (*str)
{
case 'd':
iNum = va_arg(ap, int);
printf("%d", iNum);
break;
case 'f':
dNum = va_arg(ap, double);
printf("%f", dNum);
break;
}
}
else
{
printf("%c", *str);
}
str++;
}
}
int main()
{
printf("dsds\n");
testSum();
myprint("整数:%d小数:%f\n", 12, 1.222);
return 0;
}