strtod-strtod, 字符串 转 数字 函数
strtod()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,到出现非数字或字符串结束时('\0')才结束转换,并将结果返回。若endptr不为
NULL,则会将遇到不合条件而终止的nptr中的字符指针由endptr传回。参数nptr字符串可包含正负号、小数点或E(e)来表示指数部分。如123.456或123e-2。
#include<stdlib.h>
#include<stdio.h>
void main()
{
char *endptr;
char a[] = "12345.6789";
char b[] = "1234.567qwer";
char c[] = "-232.23e4";
printf( "a=%lf\n", strtod(a,NULL) );
printf( "b=%lf\n", strtod(b,&endptr) );
printf( "endptr=%s\n", endptr );
printf( "c=%lf\n", strtod(c,NULL) );
}
执行:
a=12345.678900
b=1234.567000
endptr=qwer
c=-2322300.000000
strtol函数
#include<stdio.h>
voidmain(void)
{
char*string,*stopstring;
doublex;
intbase;
longl;
unsignedlongul;
string="3.1415926Thisstoppedit";
x=strtod(string,&stopstring);
printf("string=%s\n",string);
printf("strtod=%f\n",x);
printf("Stoppedscanat:%s\n",stopstring);
string="-10110134932Thisstoppedit";
l=strtol(string,&stopstring,10);
printf("string=%s\n",string);
printf("strtol=%ld\n",l);
printf("Stoppedscanat:%s\n",stopstring);
string="10110134932";
printf("string=%s\n",string);
/*Convertstringusingbase2,4,and8:*/
for(base=2;base<=8;base*=2)
{
/*Convertthestring:*/
ul=strtoul(string,&stopstring,base);
printf("strtol=%ld(base%d)\n",ul,base);
printf("Stoppedscanat:%s\n",stopstring);
}
}
strtod=3.141593
Stoppedscanat:Thisstoppedit
string=-10110134932Thisstoppedit
strtol=-2147483648
Stoppedscanat:Thisstoppedit
string=10110134932
strtol=45(base2)
Stoppedscanat:34932
strtol=4423(base4)
Stoppedscanat:4932
strtol=2134108(base8)
Stoppedscanat:932
strtod-strtod, 字符串 转 数字 函数的更多相关文章
- 2-2 Sass的函数功能-字符串与数字函数
Sass的函数简介 在 Sass 中除了可以定义变量,具有 @extend.%placeholder 和 mixins 等特性之外,还自备了一系列的函数功能.其主要包括: 字符串函数 数字函数 列表函 ...
- 高精度运算专题-输出函数与字符串转数字函数(Output function and the string to number function)
输出函数:这个函数别看它小,但浓缩的都是精华啊 作用:对于高精度的数组进行倒序输出 思路:首先从被传入的数组第一位开始,一直往前扫输出就可以了(i--) 注释:因为每个数组的第一位是用来存储这个数组的 ...
- JS 字符串 时间 数字函数操作 事件
字符串 操作 var s="abcdefg" s.tolowerCase() 转小写 s.toupperCase() 转大写 s.substring(2,5) 索引下 ...
- C语言--字符串和数字的相互转换
1.数字转换为字符串 sprintf 跟printf 在用法上几乎一样,只是打印的目的地不同而已,前者打印到字符串中,后者则直接在命令行上输出. sprintf 是个变参函数,定义如下: int sp ...
- c语言中字符串转数字的函数
ANSI C 规范定义了 atof().atoi().atol().strtod().strtol().strtoul() 共6个可以将字符串转换为数字的函数,大家可以对比学习.另外在 C99 / C ...
- SQL SERVER 将表中字符串转换为数字的函数 (详询请加qq:2085920154)
在SQL SERVER 2005中,将表中字符串转换为数字的函数共2个:1. convert(int,字段名) 例如:select convert(int,'3')2. cast(字段名 as i ...
- 5.单行函数,多行函数,字符函数,数字函数,日期函数,数据类型转换,数字和字符串转换,通用函数(case和decode)
1 多行函数(理解:有多个输入,但仅仅输出1个结果) SQL>select count(*) from emp; COUNT(*) ------------- 14 B 字符函数Lowe ...
- Python不使用int()函数把字符串转换为数字
Python不使用int()函数把字符串转换为数字 2018年05月21日 14:18:45 边缘ob边缘ob 阅读数:1035 https://blog.csdn.net/qq_33192555/a ...
- js数组,数字函数,字符串函数,表单验证,hashMap,堆栈,日期函数,call函数
1.javascript的数组API Js代码 收藏代码 //定义数组 var pageIds = new Array(); pageIds.push('A'); 数组长度 pageIds.lengt ...
随机推荐
- Spark SQL读parquet文件及保存
import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.sql.{Row, SparkSession} im ...
- jqgrid formatter
日期 formatter:"date",formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d'} value {name ...
- codevs1004四子连棋
1004 四子连棋 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白 ...
- [Swift通天遁地]七、数据与安全-(15)使用单元测试进行代码的性能分析
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 使用 typescript 开发 Vue
基础配置: 1. 准备一个使用 vue-cli 生成的项目 2. 使用 npm 一建安装基础配置 npm i -S @types/node typescript vue-class-component ...
- vue学习记录(一)—— vue开发调试神器vue-devtools安装
网上有些贴子少了至关重要的一步导致我一直没装上, 切记!!install后还需build,且install和build都在vue-devtools文件夹内执行 github下载地址 点击跳转 具体步骤 ...
- 【NOIP练习赛】学习
[NOIP练习赛]T3.学习 Description 巨弱小 D 准备学习,有 n 份学习资料给他看,每份学习资料的 内容可以用一个正整数 ai 表示.小 D 如果在一天内学习了多份资料, 他只能记住 ...
- Linux命令(002) -- free
一.准备知识 Linux和Windows系统在内存管理机制方面有很大的不同.在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然.这是Linux内存管理的 ...
- Docker学习系列(一):windows下安装docker(转载)
本文目录如下: windows按照docker的基本要求 具体安装步骤 开始使用 安装远程连接工具连接docker 安装中遇到的问题 Docker的更新 Docker中的jupyter windows ...
- MaBatis配置(单配置 之一)
注: 此文中的实体类还是沿用上一章的Emp和Dept两个类 .引入需要的jar包文件:http://pan.baidu.com/s/1qYy9nUc :mybatis-3.2.2.jar .编写MyB ...