C语言 函数有哪些 中文翻译都是什么意思

如题所述

第1个回答  2019-12-25
1.i/o函数
(1)scanf函数:
int
scanf(const
char
*format…..);
从标准输入流stdin中按格式format将数据写到参数表中;若操作成功,返回写到参数表中的参数个数,否则返回eof;
注意以下几点:
①scanf函数没有精度控制
如出现:
scanf(“%6.2f”,&a);
是绝对错误的
②在以%c格式输入字符数据时,所有输入的均为有效字符
如:
scanf(“%c%c%c”,&a,&b,&c);
输入:d
e
f
则a=’d’,b为空格字符'
',c=’d’
如果以%s读入字符串,则空格键和回车键都可以作为输入结束的标志
如:
scanf(“%s%s”,p,q);---------p,q均为指针
输入:hello
world与

hello

world
效果是相同的,p均指向hello这个字符串,q均指向world这个字符串
③如果在格式控制字符串中有非格式字符,则输入时要照原样入;
如:
scanf(“%d,%d,%d,”,&,&b,&c);
则输入时必须加上逗号:5,6,7
④如果同while配合用的话,则需注意去掉回车键
如有下面一段程序:
while(scanf(“%d”,&n)==1&&n!=0)
{
  char
ch;
  scanf(“%c”,&ch);
  printf(“%c\n”,ch);
}
则输出结果是:
2

3
0
结果表明ch字符是回车键
所以如果要消除影响:
有两种方法:
1)加上getchar();
while(scanf(“%d”,&n)==1&&n!=0)
{
  getchar();
  char
ch;
  scanf(“%c”,&ch);
  printf(“%c\n”,ch);
}
2)在while中加上%*c
while(scanf(“%d%*c”,&n)==1&&n!=0)即可

2.数学函数
(1)求绝对值
double
fabs(double
);
float
fabsf(float);
long
double
fabsl(long
double);
int
abs(int);
long
int
labs(long
int);
(2)floor函数:返回不大于参数的整数
float
floor(float);
double
floor(double);
(3)ceil函数:返回不小于参数的整数
float
ceil(float);
double
floor(double);
(4)pow:返回x^y;
double
pow(double
x,double
y);
(5)sqrt:返回x的开方
double
sqrt(double
x);
(6)log2,log10:返回底数的自然对数值
double
log2(double
x);
double
log10(double
x);

3.字符串处理函数
(1)char
*strchr(const
char
*str,int
ch);

返回str中第一次出现字符ch的位置指针,否则返回null;
(2)char
*strstr(const
char
*str1,const
char
*str2);

返回str1中第一次出现str2的位置指针,否则返回null;
(3)int
stricmp(const
char
*str1,const
char
*str2);

忽略字符的大小写进行比较
(4)int
strncmp(const
char
*str1,const
char
*str2,int
count);

将str1前n个字符与str2的前n个字符进行比较
(5)char
*strncpy(char
*str1,const
char
*str2,int
count);

将str2的前n个字符复制到str1中
(6)char
*strrev(char
*str);
将字符串str逆序,并返回逆置后的结果

4.常用使用函数
(1)double
atof(const
char
*str);

将字符串str表示的数转换成浮点数
(2)int
atoi(const
char
*str);

将字符串str表示的数转换成整数
(3)void
qsort(void
*buf,int
count,int
size,cmp);————>count为所需要进行排序的元素个数,size为每个元素所占用的空间

快速排序
相似回答