#include 「stdlib.h」

下面是自我测试

  • | “3.14” --> 3.14 ,怎么实现
  • | “3” --> 3 ,怎么实现
  • | “88888888888” --> 88888888888,怎么实现
  • | “3.14yqj” --> 3.14 + “yqj”,怎么实现
  • | “8888888888yqj” --> 88888888888 + “yqj” ,怎么实现
  • | 两种申请栈内存的方法,不建议使用哪一个,重新设置栈内存的方法,如何释放栈内容
  • | 异常退出进程函数,正常退出进程函数
  • | main函数结束后跳转到function1函数,如何实现
  • | 获取环境变量的函数
  • | 如何在代码中运行Linux命令
  • | 二分法查找函数
  • | 排序函数
  • | 求绝对值函数
  • | 数学除法
  • | 产生随机数,如何产生随机数种子,如何获unix时间
  • | 二分法与排序函数都需要一个对比函数,默写一下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
	1:atof()  
	{
		作用:"数字" --> 数字  
		注意:返回值为double;
	}
	2:atoi()  
	{
		作用:"数字" --> 数字  
		注意:返回值为int;
	}
	3:atol()
	{
		作用:"数字" --> 数字
		注意:返回值为long int;
	}
	4: strtod()
	{
		作用:"数字 + 字符" --> 数字 + "字符";
		注意:
		{
			返回的数字为double;
			数字必须在字符前面,否则不能正确拆分
		}
	}

	5:strtol()
	{
		作用:"数字 + 字符" --> 数字 + "字符";
		注意:
		{
			返回的数字为long int;
			数字必须在字符前面,否则不能正确拆分
			参数3:表示返回的数是多少进制的!
		}	
	}

	6:strtoul()
	{
		作用:"数字 + 字符" --> 数字 + "字符";
		注意:
		{
			返回的数字为unsigned long;
			数字必须在字符前面,否则不能正确拆分
			参数3:表示返回的数是多少进制的!
		}
	}

	7:calloc()  //解决地址指针无法获取数据,例如char * Eng ; Eng =getchar(); x  --> 必须确定子空间个数与子空间大小才会有获取数据的权限!
	{
		作用:为地址分配空间

		当你需要建立一个临时的地址空间,并且用指针的形式来获取存储
		参数一:子空间个数
		参数二:子空间大小	
	}

	8:malloc() //解决地址指针无法获取数据,例如char * Eng ; Eng =getchar(); x  --> 必须确定子空间个数与子空间大小才会有获取数据的权限!
	{
		作用:为地址分配空间

		当你需要建立一个临时的地址空间,并且用指针的形式来获取存储
		
		参数:空间大小!
	}

	9:realloc()
	{
		重新调整malloc/calloc的空间大小

		参数一:地址
		参数二:调整后的大小
	}

	10:free()  //释放掉malloc/calloc/realloc的空间!

	11:	abort()  //强制终止程序,并跳出因abort产生消息框!

	12:atexit()  //注册需要在主函数结束后执行的函数!,并在程序终止时调用!

	13:exit();  //与abort不同,exit是正常退出程序!
	{
		0 = 正常退出
		-1 = 异常退出
	}

	14:getenv()  //返回系统环境变量的磁盘位置!
	15:system()  //调用dos命令行,能直接调用system系统

	16:bsearch()
	{
		参数一:需要找的数的地址  //要拿去与数组比较
		参数二:待比较数组
		参数三:数组元素个数
		参数四:数组元素的字节  //因为不同位数的系统处理字不一样!
		参数五:用于比较参数1与参数2的数组的函数
			{
				不用写参数,参数分别为const void * a,const void * b
				注意:
					泛型的传进来的实参还需要转化为具体多少字节类型的参数!
					bearch与qsort的比较函数都是一样的!
			}
		返回值:参数一的地址!  --> 表示找到的意思!
	}

	17:qsort()  //对数组进行排序
	{
		参数一:数组地址!
		参数二:数组元素的个数!
		参数三:数组元素的大小!
		参数四:比较函数,写法与格式都是默认的!
		返回值:无!
	}

	18:
	{
		abs(x)  //int 绝对值;
		labs(x)  //long int 绝对值;
		llabs(x)  //long long int 绝对值;
	}

	19:
	div_t结构体  //int
	{
		div->quot = 商;
		div->rem = 余数;
	}
	div_t结构体 = div(x,y) //x 除以 y;商与余数被放在div_t结构体,就不用苦苦想名字了,而且还用结构体分类了!

	ldiv_t结构体  //long int
	{
		ldiv->quot = 商;
		ldiv->rem = 余数;
	}
	ldiv_t结构体 = ldiv(x,y) //x 除以 y;商与余数被放在div_t结构体,就不用苦苦想名字了,而且还用结构体分类了!

	20:rand() % x //产生[0.x]的随机整数
	{
		注意:由于没设种子,每次随机产生的结果都一样!
	}

	21:srand(time(time_t 结构体变量))
	{
		作用:仅仅是设立种子之后的由rand()产生的结果每一秒都是不一样的!
		
		参数:time()  //根据时间不同,确保不会产生一样的rand()!
	}	



	22:mblen()  ???????????
	{
		wchar_t : wchar_t数据类型一般为16位或32位/char是8位字符类型,最多只能包含256种字符,所以,汉字数量大char完全不能表示完,可以用宽字符表示!
	}


	
*/


void Lib_text1()
{
	char* Number = "3.14";
	
	double Number_Trans = atof(Number);

	printf("转化后的浮点值为:%lf", Number_Trans);

	
}

void Lib_text2()
{
	char* Number = "3.14";

	int Number_Trans = atoi(Number);

	printf("转化后的整型为:%d", Number_Trans);
}

void Lib_text3()
{
	char* Number = "3.14";

	int Number_Trans = atol(Number);

	printf("转化后的整型为:%ld", Number_Trans);
}


void Lib_text4()
{
	
	char* Str = "201703836我的编号";

	double Number ; 

	char* Eng;

	Number = strtod(Str, &Eng);

	printf("\n提取出的数字:%lf\n", Number);
	printf("\n提取出的字符:%s\n", Eng);
	
	
}


void Lib_text5()
{

	char* Str = "201703836我的编号";

	long int Number;

	char* Eng;

	Number = strtol(Str, &Eng,10);

	printf("\n提取出的数字:%ld\n", Number);
	printf("\n提取出的字符:%s\n", Eng);

}

void Lib_text6()
{

	char* Str = "201703836我的编号";

	long int Number;

	char* Eng;

	Number = strtoul(Str, &Eng, 10);

	printf("\n提取出的数字:%u\n", Number);
	printf("\n提取出的字符:%s\n", Eng);

}


void Lib_text7()
{

	char* Str;

	Str = (char*)calloc(5, sizeof(char));

	for (size_t i = 0; i < 5; i++)
	{
		Str[i] = getchar();
		putchar(Str[i]);
	}
	free(Str);
}


void Lib_text8()
{

	char* Str;

	Str = (char*)malloc(5);

	for (size_t i = 0; i < 5; i++)
	{
		Str[i] = getchar();
		putchar(Str[i]);
	}
	free(Str);
}


void Lib_text9()
{

	char* Str;

	Str = (char*)malloc(5);

	realloc(Str, 10);

	for (size_t i = 0; i < 10; i++)
	{
		Str[i] = getchar();
		putchar(Str[i]);
	}
	free(Str);

}

void Lib_text11()
{
	FILE* fp;

	fp = fopen("text10.txt", "r");

	if (fp == NULL)
	{
		perror("");
		printf("正在关闭程序!\n");
		
		abort();
	}
}

void Lib_text12_exit()
{
	printf("主函数结束后执行!\n");
}

void Lib_text12()
{
	printf("程序执行....\n");
	printf("程序结束....\n");

	atexit(Lib_text12_exit);
}

void Lib_text13()
{
	printf("程序执行....\n");
	printf("程序结束....\n");
	exit(0);
}

void Lib_text14()
{
	printf("PATH的路径:%s", getenv("PATH"));

	exit(0);
}

void Lib_text15()
{
	system("ipconfig");
}

int cmpfunc(const void* a, const void* b)
{
	return (*(char*)a - *(char*)b);
}


void Lib_text16()
{
	char *values = "hello!";
	char* item;
	char key = 'h';

	item = (char*)bsearch(&key, values, 6, sizeof(char), cmpfunc);
	if (item != NULL)
	{
		printf("Found item = %c\n", *item);
	}
	else
	{
		printf("Item = %c could not be found\n", *item);
	}
	return(0);
}


void Lib_text17()
{
	int Array[] = { 10, 30, 90, 80, 70, 40 };

	qsort(Array, sizeof(Array) / sizeof(int), sizeof(int), cmpfunc);

	for (size_t i = 0; i < sizeof(Array) / sizeof(int); i++)
	{
		printf("%d\n", Array[i]);
	}

	return(0);
}

void Lib_text18()
{
	printf("%d\n", abs(-1));
	printf("%ld\n", labs(-123456789));
	printf("%lld\n", llabs(-1111111111123456789));
}

void Lib_text19()
{
	div_t My_Div;
	ldiv_t My_Ldiv;

	My_Div = div(27, 4);
	My_Ldiv = ldiv(11111111111111, 2);

	printf("商:%d\n",My_Div.quot);
	printf("余数:%d\n",My_Div.rem);


	printf("商:%d\n", My_Ldiv.quot);
	printf("余数:%d\n", My_Ldiv.rem);

}


void Lib_text20()
{
	for (size_t i = 0; i < 10; i++)
	{
		printf("\n随机数%d:%d\n", i + 1, rand() % 100);
	}
}



void Lib_text21()
{

	time_t MyTime;
	srand(time(&MyTime));

	for (size_t i = 0; i < 10; i++)
	{
		printf("\n随机数%d:%d\n", i + 1, rand() % 100);
	}
}

void Lib_text22()
{
	wchar_t* Eng =L"あ";
	printf("%d", mblen(Eng, 1));
}

void STDLIB_TEXT()
{
	//atof()使用方法
	//Lib_text1();

	//atoi()使用方法
	//Lib_text2();

	//atol()使用方法
	//Lib_text3();

	//strtod()使用方法
	//Lib_text4();

	//strtol()使用方法
	//Lib_text5();

	//strtoul()使用方法
	//Lib_text6();

	//calloc()使用方法
	//Lib_text7();

	//malloc()使用方法
	//Lib_text8();

	//realloc()使用方法
	//Lib_text9();

	//abort()使用方法
	//Lib_text11();

	//atexit()使用方法
	//Lib_text12();

	//exit()使用方法
	//Lib_text13();

	//getenv()使用方法
	//Lib_text14();

	//system()使用方法
	//Lib_text15();

	//bsearch()使用方法
	//Lib_text16();

	//qsort()使用方法
	//Lib_text17();

	//abs(),labs(),llabs()使用方法
	//Lib_text18();

	//div().ldiv()使用方法
	//Lib_text19();

	//rand()使用方法
	//Lib_text20();

	//srand()使用方法
	//Lib_text21();

	//mblen()使用方法
	Lib_text22();
}

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值