@函数名称:
calloc
函数原型:
void * calloc(unsigned n,unsign size);
函数功能:
分配n个数据项的内存连续空间,每个数据项的大小为size
函数返回:
分配内存单元的起始地址,如果不成功,返回0
所属文件:
<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *str=NULL;
str=calloc(10,sizeof(char));
strcpy(str,"Hello");
printf("String is %s",str);
free(str);
return 0;
}
@函数名称:
free
函数原型:
void free(void* p);
函数功能:
释放p所指的内存区
参数说明:
p-被释放的指针
所属文件:
<stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *str;
str=malloc(10);
strcpy(str,"Hello");
printf("String is %s",str);
free(str);
return 0;
}
@函数名称:
malloc
函数原型:
void * malloc(unsigned size);
函数功能:
分配size字节的存储区
函数返回:
所分配的内存区地址,如果内存不够,返回0
参数说明:
所属文件:
<stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char *str;
if((str=malloc(10))==NULL)
{
printf("Not enough memory to allocate buffer");
exit(1);
}
strcpy(str,"Hello");
printf("String is %s",str);
free(str);
return 0;
}
@函数名称:
realloc
函数原型:
void * realloc(void * p,unsigned size);
函数功能:
将p所指出的已分配内存区的大小改为size,size可以比原来分配的空间大或小
函数返回:
返回指向该内存区的指针.NULL-分配失败
参数说明:
所属文件:
<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str;
str= malloc(10);
strcpy(str,"Hello");
printf("String is %s Address is %p",str,str);
str=realloc(str,20);
printf("String is %s New address is %p",str,str);
free(str);
return 0;
}
@函数名称:
rand
函数原型:
int rand(void);
函数功能:
产生0到32767间的随机整数(0到0x7fff之间)
函数返回:
随机整数
参数说明:
所属文件:
<stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i;
printf("Ten random numbers from 0 to 99");
for(i=0;i<10;i++)
printf("%d",rand()%100);
return 0;
}
@函数名称:
abort
函数原型:
void abort(void)
函数功能:
异常终止一个进程.
函数返回:
参数说明:
所属文件:
<stdio.h>,<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("call abort()");
abort();
return 0;
}
@函数名称:
exit
函数原型:
void exit(int state)
函数功能:
程序中止执行,返回调用过程
函数返回:
参数说明:
state:0-正常中止,非0-非正常中止
所属文件:
<stdlib.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
int main()
{
int status;
printf("put a key\n");
status=getch();
exit(0);
return 0;
}
@函数名称:
getenv
函数原型:
char* getenv(const char *name)
函数功能:
返回一个指向环境变量的指针
函数返回:
环境变量的定义
参数说明:
name-环境字符串
所属文件:
<stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char *s;
s=getenv("COMSPEC");
printf("Command processor:%s",s);
return 0;
}
@函数名称:
putenv
函数原型:
int putenv(const char *name)
函数功能:
将字符串name增加到DOS环境变量中
函数返回:
0:操作成功,-1:操作失败
参数说明:
name-环境字符串
所属文件:
<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>
int main()
{
char *path,*ptr;
int i=0;
ptr=getenv("PATH");
path=malloc(strlen(ptr)+15);
strcpy(path,"PATH=");
strcat(path,ptr);
strcat(path,";c:\temp");
putenv(path);
while (environ[i])
printf("%s",environ[i++]);
return 0;
}
@函数名称:
labs
函数原型:
long labs(long num)
函数功能:
求长整型参数的绝对值
函数返回:
绝对值
参数说明:
所属文件:
<stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
long result;
long x=-12345678L;
result= labs(x);
printf("number: %ld abs value: %ld",x,result);
return 0;
}
@函数名称:
atof
函数原型:
double atof(char *str)
函数功能:
将字符串转换成一个双精度数值
函数返回:
转换后的数值
参数说明:
str-待转换浮点型数的字符串
所属文件:
<stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
float f;
char *str="12345.67";
f=atof(str);
printf("string=%s float=%f",str,f);
return 0;
}