下面是自我测试
| “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>
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()
{
Lib_text22();
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-53919.html