首页 > 编程语言 > 详细

c语言中转换字符串函数 atoi函数

时间:2021-06-02 00:00:35      阅读:17      评论:0      收藏:0      [点我收藏+]

1、c语言中转换字符串函数 atoi将字符型转换为int型。

c语言标准函数库提供了字符串转换函数。 <stdlib.h>。

#include <stdio.h>
#include <stdlib.h>  //c语言标准函数库

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    printf("convert to int type: %d\n", atoi(str));
    return 0;
}

技术分享图片

 

 

2、转换为double型

#include <stdio.h>
#include <stdlib.h> //c语言标准函数库 

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    printf("after converting to dougle type: %f\n", atof(str));
    
    return 0;
}

技术分享图片

 

c语言中转换字符串函数 atoi函数

原文:https://www.cnblogs.com/liujiaxin2018/p/14838972.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!