four:

来源:互联网 发布:淘宝充值平台退款 编辑:程序博客网 时间:2024/04/30 06:29

atoi :

 

函数名: atoi
功 能: 把字符串转换成整型数
函数说明: atoi()会扫描参数nptr字符串,检测到第一个数字或正负符号时开始做类型转换,之后检测到非数字或结束符 /0 时停止转换,返回整型数。
用 法: int atoi(const char *nptr);
需要用到的头文件: #include <stdlib.h>
程序例:
1)
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
int n;
char *str = "12345.67";

n = atoi(str);
printf("string = %s integer = %d/n", str, n);
return 0;
}
执行结果
string = 12345.67 integer = 12345

2)
#include <stdlib.h>
#include <stdio.h>
int mian()
{
    char a[] = "-100" ;
    char b[] = "123" ;
    int c ;
    c = atoi( a ) + atoi( b ) ;
    printf("c = %d/n", c) ;
    return 0;
}
执行结果
c = 23

 

 

 

strrchr

 

strrchr() 函数

Definition and Usage
定义和用法

The strrchr() function finds the position of the last occurrence of a string within another string, and returns all characters from this position to the end of the string.
strrchr()函数的作用是:查找一个字符串在另一个字符串中末次出现的位置,并返回从字符串中的这个位置起,一直到字符串结束的所有字符。

If char cannot be found, this function returns FALSE.
如果未能找到指定字符,那么函数将返回False。

Syntax
语法

strrchr(string,char)

Parameter参数 Description描述
string Required. Specifies the string to search
必要参数。指定需要进行搜索的字符串
char Required. Specifies the string to find. If this is a number, it will search for the character matching the ASCII value of that number
必要参数。指定需要查找的字符对象。如果是一个数字,那么他将搜索与这个数字对应的ASCII值相匹配的字符


Tips and Notes
提示

Tip: This function is binary safe.
提示:这个函数是二进制精确的。


Example 1
案例1

<?phpecho strrchr("Hello world!","world");?>

The output of the code above will be:
上述代码将输出下面的结果:

world!


Example 2
案例2

In this example we will search a string for the ASCII value of "o":
在下的案例中,我们将输入“o”的ASCII值:

<?phpecho strrchr("Hello world!",111);?>

The output of the code above will be:
上述代码将输出下面的结果:

orld!


原创粉丝点击