C标准库学习stdlib.h

/***
*stdlib.h
****/
...


/* exit()函数返回定义*/
#define EXIT_SUCCESS    0
#define EXIT_FAILURE    1
。。。

/* Data structure definitions for div and ldiv runtimes. */

#ifndef _DIV_T_DEFINED

//div函数返回结构
typedef struct _div_t {
        int quot; //商
        int rem;  //余数
} div_t;
//ldiv函数返回结构
typedef struct _ldiv_t {
        long quot;
        long rem;
} ldiv_t;

#define _DIV_T_DEFINED
#endif


/* rand函数可以返回的最大值. */

#define RAND_MAX 0x7fff

/*
 * Maximum number of bytes in multi-byte character in the current locale
 * (also defined in ctype.h).
 */
#ifndef MB_CUR_MAX
#define MB_CUR_MAX __mb_cur_max
_CRTIMP extern int __mb_cur_max;
#endif  /* MB_CUR_MAX */


/* Minimum and maximum macros */

#define __max(a,b)  (((a) > (b)) ? (a) : (b))
#define __min(a,b)  (((a) < (b)) ? (a) : (b))

/*
 * Sizes for buffers used by the _makepath() and _splitpath() functions.
 * note that the sizes include space for 0-terminator
 */
#ifndef _MAC
#define _MAX_PATH   260 /* 全路径最大长度 */
#define _MAX_DRIVE  3   /* 驱动符 */
#define _MAX_DIR    256 /* 目录*/
#define _MAX_FNAME  256 /* 文件名称 */
#define _MAX_EXT    256 /* max. length of extension component */
 
/*
 * Argument values for _set_error_mode().
 */
#define _OUT_TO_DEFAULT 0
#define _OUT_TO_STDERR  1
#define _OUT_TO_MSGBOX  2
#define _REPORT_ERRMODE 3

...


_CRTIMP extern char * _sys_errlist[];   /* perror error message table */
_CRTIMP extern int _sys_nerr;           /* # of entries in sys_errlist table */
...


/* Windows major/minor and O.S. version numbers */

_CRTIMP extern unsigned int _osver;
_CRTIMP extern unsigned int _winver;
_CRTIMP extern unsigned int _winmajor;
_CRTIMP extern unsigned int _winminor;


/* function prototypes */

 ...
void   abort(void);
void   exit(int);
 
...
int    abs(int);
long   labs(long);


int    atexit(void (*)(void));

//转换函数
double atof(const char *);
int    atoi(const char *);
long   atol(const char *);
long double _atold(const char *);
char * _itoa(int, char *, int);
char * _i64toa(__int64, char *, int);
char * _ui64toa(unsigned __int64, char *, int);
__int64 _atoi64(const char *);
char * _ltoa(long, char *, int);
double strtod(const char *, char **);
long   strtol(const char *, char **, int);
...
long double _strtold(const char *, char **);
unsigned long strtoul(const char *, char **, int);

char * _ultoa(unsigned long, char *, int);
int    wctomb(char *, wchar_t);
size_t wcstombs(char *, const wchar_t *, size_t);
int    mbtowc(wchar_t *, const char *, size_t);
size_t mbstowcs(wchar_t *, const char *, size_t);

//
void * bsearch(const void *, const void *, size_t, size_t,
        int (*)(const void *, const void *));

//取得环境变量内容
char * getenv(const char *);
如果该变量存在则会返回指向该内容的指针。环境变量的格式为name=value。
返回值
    执行成功则返回指向该内容的指针,找不到符合的环境变量名称则返回NULL。
范例
    #include<stdlib.h>
mian()
{
char *p;
if((p = getenv(“USER”)))
printf(“USER=%s/n”,p);
}
执行
    USER = root

//除法
div_t  div(int, int);
ldiv_t ldiv(long, long);

//内存的分配和释放
void* calloc (size_t, size_t); 分配内存, 并清零
void* malloc (size_t);  分配内存
void* realloc (void*, size_t); 重新分配内存, 返回新指针
void free (void*);  释放内存

//
int    mblen(const char *, size_t);
size_t _mbstrlen(const char *s);


//排序
void   qsort(void *, size_t, size_t, int (*)
        (const void *, const void *));
//随机
int    rand(void);  //随机函数(range 0 to RAND_MAX)
void   srand(unsigned int);

//
int    _set_error_mode(int);




 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值