tolower() 把英文字母转换成小写,非字母字符不做出处理 ctype.h中
toupper() 把英文字母转换成大写,非字母字符不做出处理 ctype.h中
memset() 原型:void *memset(void *s, int ch, size_t n) 将s所指向的某一块内存中的前n个 字节(每个字节每个字节的赋)的内容全部设置为ch指定的ASCII值 stdlib.h中 返回值为指向s的指针 如: int s[100],memset(s,0,sizeof(s)); char s[100];memset(s,'*',sizeof(s));
qsort() 原型:void qsort(void*base,size_t num,size_t width,int(__cdecl*compare)(const void*,const void*)) 各参数:1 待排序数组首地址 2 数组中 待排序元素数量 3 各元素的占用空间大小 4 指向函数的指针 使用快速排序历程进行排序 stdlib.h中 如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include<stdio.h>
#include<stdlib.h>
int
comp(
const
void
*a,
const
void
*b)
{
return
*(
int
*)a-*(
int
*)b;
}
int
main()
{
int
i=0;
int
*array;
int
n;
scanf
(
"%d"
,&n);
array=(
int
*)
malloc
(n*
sizeof
(
int
));
for
(;i<n;i++)
{
scanf
(
"%d"
,(array+i));
}
qsort
(array,n,
sizeof
(
int
),comp);
for
(i=0;i<n;i++)
{
printf
(
"%d\t"
,array[i]);
}
return
0;
}
|
1
2
3
4
5
6
7
|
qsort
(a,1000,
sizeof
(
int
)*2,comp);
int
comp(
const
void
*a,
const
void
*b)
{
return
((
int
*)a)[0]-((
int
*)b)[0];
}
|
1
2
3
4
5
6
7
8
9
10
|
int
Comp(
const
void
*p1,
const
void
*p2)
{
return
strcmp
((
char
*)p2,(
char
*)p1);
}
int
main()
{
char
a[MAX1][MAX2];
initial(a);
qsort
(a,lenth,
sizeof
(a[0]),Comp);
//lenth为数组a的长度
|
1
2
3
4
5
6
7
8
9
10
|
structNode
{
double
data;
int
other;
}s[100];
int
Comp(constvoid*p1,constvoid*p2)
{
return
(*(Node*)p2).data>(*(Node*)p1).data?1:-1;
}
qsort
(s,100,
sizeof
(s[0]),Comp);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
struct
Node
{
int
x;
int
y;
}s[100];
//按照x从小到大排序,当x相等时按y从大到小排序
int
Comp(
const
void
*p1,
const
void
*p2)
{
struct
Node*c=(Node*)p1;
struct
Node*d=(Node*)p2;
if
(c->x!=d->x)returnc->x-d->x;
else
return
d->y-c->y;
}
|
1
2
3
4
5
6
7
8
9
10
11
|
struct
Node
{
int
data;
char
str[100];
}s[100];
//按照结构体中字符串str的字典序排序
int
Comp(
const
void
*p1,
const
void
*p2)
{
return
strcmp
((*(Node*)p1).str,(*(Node*)p2).str);
}
qsort
(s,100,
sizeof
(s[0]),Comp);
|
1
2
3
4
5
6
7
8
9
10
11
|
int
Comp(
const
void
*p1,
const
void
*p2)
//重点Comp函数,把除了1点外的所有的点旋转角度排序
{
struct
point*c=(point*)p1;
struct
point*d=(point*)p2;
if
(cacl(*c,*d,p[1])<0) return1;
elseif(!cacl(*c,*d,p[1])&&dis(c->x,c->y,p[1].x,p[1].y)<dis(d->x,d->y,p[1].x,p[1].y))
//如果在一条直线上,则把远的放在前面
return1;
elsereturn-1;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// crt_sprintf.c
// compile with: /W3
// This program uses sprintf to format various
//data and place them in the string named buffer.
// 程序使用sprintf 将各种数据格式化后置于字符数组buffer中
#include <stdio.h>
int
main(
void
)
{
char
buffer[200], s[] =
"computer"
, c =
'l'
;
int
i = 35, j;
float
fp = 1.7320534f;
// 格式化并打印各种数据到buffer
j =
sprintf
( buffer,
" String: %s\n"
, s );
// C4996
j +=
sprintf
( buffer + j,
" Character: %c\n"
, c );
// C4996
j +=
sprintf
( buffer + j,
" Integer: %d\n"
, i );
// C4996
j +=
sprintf
( buffer + j,
" Real: %f\n"
, fp );
// C4996
printf
(
"Output:\n%s\ncharacter count = %d\n"
, buffer, j );
}
|
-
中文名
- atof() 外文名
- ascii to floating point numbers
-
释 义
- . 函数名 功 能
- 把字符串转换成浮点数
1
2
3
4
5
6
7
8
9
10
|
#include<stdlib.h>
#include<stdio.h>
int
main()
{
double
d;
char
str[] =
"123.456"
;
d=
atof
(str);
printf
(
"string=%sdouble=%lf\n"
,str,d);
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
|
#include<stdlib.h>
int
main()
{
char
*a=
"-100.23"
;
char
*b=
"200e-2"
;
doublec;
c=
atof
(a)+
atof
(b);
printf
(“c=%.2lf\n”,c);
return
0;
}
|