atoi()函数

atoi(全称:ASCII to integer)是一个函数名,意思是把字符串转换成整型数。
atoi (表示 alphanumeric to integer)是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中。

函数说明:
  参数nptr字符串,如果第一个非空格字符存在,是数字或者正负号则开始做类型转换,之后检测到非数字(包括结束符 \0) 字符时停止转换,返回整型数。否则,返回零。
  包含在头文件stdlib.h中。

/***************************************************************

File Name: 2.c
Author: 浮生流年
Function List: main() 主函数
Created Time: 2017年12月22日 星期五 20时17分14秒
**************************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[20] = "12345.67";//检测到非数字字符'.'后停止转换,返回整形数
    char b[20] = "-100";
    char c[20] = "123";

    printf("%d\n", atoi(a));
    printf("%d\n", atoi(b));
    printf("%d\n", atoi(c));

    return 0;
}

这里写图片描述

/***************************************************************

File Name: case.c
Author: 浮生流年
Function List: main() 主函数
Created Time: 2017年12月18日 星期一 12时24分25秒
**************************************************************/

#include <stdio.h>
#include <string.h>
int main()
{
    char a[20] = {0};
    char b[20] = {0};
    char c[20] = {0};

    strcpy(a, "9点赞成功");
    strcpy(b, "10点赞失败");
    strcpy(c, "11个性签名修改成功");

    printf("%d\t", atoi(a));
    printf("%d\t", atoi(&a[0]));
    printf("%d\t", atoi(&a[1]));
    printf("%d\n", atoi(&a[0]) + atoi(&a[1]));

    printf("%d\t", atoi(b));
    printf("%d\t", atoi(&b[0]));
    printf("%d\t", atoi(&b[1]));
    printf("%d\n", atoi(&b[0]) + atoi(&b[1]));

    printf("%d\t", atoi(c));
    printf("%d\t", atoi(&c[0]));
    printf("%d\t", atoi(&c[1]));
    printf("%d\t", atoi(&c[0]) + atoi(&c[1]));

    return 0;
}

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮生卍流年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值