下面是自我检测的区域,查看题目,自我回答,感觉自己掌握了就可以打勾
-
将"2020"转化成整数2020,是什么函数
-
将"3,1415"转化成浮点数3.1415,是什么函数
-
将"8888888888"转化为长整型8888888888是什么函数
-
将"3.1415yqj"这种数字与字符组合的拆分成3.1415与"yqj"是什么函数
-
将"8888888888yqj"这种数字与字符组合的拆分成8888888888与"yqj"是什么函数
-
将"88yqj"这种数字与字符组合的拆分成88与"yqj"是什么函数
-
申请栈内存的函数叫什么,重新分配堆空间大小的函数叫什么,最后还要记得不要忘记干嘛? //不推荐使用哪个函数
-
结束进程是哪个函数,由于异常结束进程是哪个函数,正常退出主函数原则程序就结束了,但是还能跳转到其他函数,应该如何实现
-
如何打印系统变量的值
-
如何在程序里面运行shell命令
-
有一个很大数据库,并且是乱序的,要求把数据排好序,并且用二分法快速找到其中一个数据,怎么做;里面有个比较函数需要自己写,默写一下这个函数
-
main函数前面声明一个函数,这个函数的传参格式是什么样的,请默写
-
求绝对值的函数是什么,求一个很大的数的绝对值的函数是什么
-
数学上的除法函数是什么,能得到余数与除数的,如果很大的数的除法函数是什么
-
怎么产生一个随机数;怎么产生种子,请简述代码流程
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void func1()
{
printf("\nmain函数结束后进入此函数\n");
}
int cmpfunc(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main(int argc, char *argv[])
{
//函数1:atof()
char *p1 = "3.1415";
printf("\n函数1结果:%f\n",atof(p1));
//函数2:atoi()
char *p2 = "1";
printf("\n函数2结果:%d\n",atoi(p2));
//函数3:atol()
char *p3 = "1";
printf("\n函数3结果:%d\n",atol(p3));
//函数4:strtod(),将字符串的字符部分与数字(double浮点数)部分拆开
char *p4 = "3.14yqj";
char *p4_1;
printf("\n函数4提取的数字结果:%lf\n",strtod(p4,&p4_1));
printf("\n函数4提取的字符结果:%s\n",p4_1);
//函数5:strtol(),将字符串的字符部分与数字(long 长整型)部分拆开
char *p5 = "123yqj";
char *p5_1;
printf("\n函数5提取的数字结果:%ld\n",strtol(p5,&p5_1,10));
printf("\n函数5提取的字符结果:%s\n",p5_1);
//函数6:strtoul()
//将字符串的字符部分与数字(long 无符号长整型)部分拆开
char *p6 = "123yqj";
char *p6_1;
printf("\n函数6提取的数字结果:%lu\n",strtol(p6,&p6_1,10));
printf("\n函数6提取的字符结果:%s\n",p6_1);
//函数7:calloc(),申请栈内存
//函数7.1:free(),释放栈
int *p7;
int i;
printf("\n函数7结果:");
p7 = (int*)calloc(5,sizeof(int));
for( i=0 ; i < 5 ; i++ )
{
p7[i] = i;
printf("%d\t",p7[i]);
}
free(p7);
printf("\n");
//函数8:malloc(),申请char类型栈内存
//会用alloc就ok,尽量不用malloc
char *p8;
p8 = (char*)malloc(20);
strcat(p8,"\n函数8结果\n");
puts(p8);
free(p8);
//函数9:realloc(),重新调整大小
char *p9;
p9 = (char*)calloc(5,sizeof(char));
strcpy(p9,"123456789");
printf("\n函数9:alloc >> %s\n",p9);
p9 = (char*)realloc(p9,10);
printf("\n函数9:realloc >> %s\n",p9);
//函数10:abort();使一个异常程序终止
printf("\n");
int p10 = 0;
if(p10 == 1)
{
abort();
}
printf("\n");
//函数11:atexit(),程序正常终止时,调用指定的函数
int p11 = 0;
if(p11 == 1)
{
atexit(func1);
}
//函数12:exit(), 参数所该进程的状态值
int p12 = 0;
if (p12 == 1)
{
exit(0);
}
//函数13:getenv(),打印一些系统变量
//例如PATH不能直接用%s打印,只能用这种方法获取
printf("\n函数13:PATH is %s\n",getenv("PATH"));
//函数14:system(),能在C文件里面运行linux的命令
printf("\n");
system("ls");
printf("\n");
//函数15:bsearch(),二分查找 ,注意二分查找必须是拍好顺序的
int Array[5] = {
1,2,3,4,5};
int x = 4;
int *p15;
p15 = (int *)bsearch(&x,Array,5,sizeof(int),cmpfunc);
printf("\n函数15:结果是%d\n",*p15);
//函数16:qsort(),对数组进行排序。
int Array1[5] = {
20,10,30,50,40};
qsort(Array1, 5, sizeof(int), cmpfunc);
printf("\n函数16:排序之后的列表 \n");
for( i = 0 ; i < 5; i++ ) {
printf("%d \t", Array1[i]);
}
//函数17,abs(),求绝对值
printf("\n\n函数17:%d\n",abs(-10));
//函数18:div(), /与%的结合
div_t output;
printf("\n函数18:\n");
output = div(27,4);
printf("(27/4) 的商 = %d\n", output.quot);
printf("(27/4) 的余数 = %d\n", output.rem);
//函数19:labs(),long int 的绝对值
printf("\n函数19:%ld\n",labs(-11111111111));
//函数20:ldiv(),
ldiv_t output1;
printf("\n函数20:\n");
output1 = ldiv(10000000000, 3000000);
printf("商 = %ld\n", output1.quot);
printf("余数 = %ld\n", output1.rem);
//函数21:rand(),srand()
/* 初始化随机数发生器 */
time_t t;
srand(time(&t));
printf("\n函数21:\n");
for( i = 0 ; i < 5 ; i++ )
{
printf("%d\n", rand() % 50);
}
}
============================
结果如下:
topeet@ubuntu:~/Desktop$ ./a.out
函数1结果:3.141500
函数2结果:1
函数3结果:1
函数4提取的数字结果:3.140000
函数4提取的字符结果:yqj
函数5提取的数字结果:123
函数5提取的字符结果:yqj
函数6提取的数字结果:123
函数6提取的字符结果:yqj
函数7结果:0 1 2 3 4
函数8结果
函数9:alloc >> 123456789
函数9:realloc >> 123456789
函数13:PATH is /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/topeet/arm-2009q3/bin
1.c 2.c a.out
函数15:结果是4
函数16:排序之后的列表
10 20 30 40 50
函数17:10
函数18:
(27/4) 的商 = 6
(27/4) 的余数 = 3
函数19:11111111111
函数20:
商 = 3333
余数 = 1000000
13
18
21
23
47
============================