常用的函数:atoi,itoa,atof,_ttoi等

出自http://blog.csdn.net/zzyoucan/article/details/10260093

atoi---ASCII to integer,将字符串转换成整形,从数字或正负号开始转换,一直到非数字为止

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. float n;
  6. char *str = "12345.67";
  7. n = atoi(str);
  8. printf("string = %s integer = %d\n", str, n);
  9. return 0;
  10. }

其他的几个类似
itoa---integer to ASCII--将整形转换成字符串

atof---ascii to float--字符串转换成浮点型

atol---ascii to long---字符串转换成长整形

gcvt---浮点型转换成字符串(四舍五入)

strtod---字符串转换成浮点型

strtol---字符串转换成长整形

strtoul--字符串转换成无符号长整形

toascii---将整形转换成合法的ASCII码字符

_ttoi---可以将CString转换成整形

_itot_s---将int转换成char*

    1. CWnd * pWnd = (CWnd*)GetDlgItem(IDC_EDIT4) ;
    2. CString strValue ;
    3. pWnd->GetWindowText(strValue) ;
    4. strValue.Replace(_T("sec"), _T("")) ;
    5. int iValue = _ttoi(strValue) ;//将Cstring转换成int
    6. TCHAR buffer[7] ;
    7. _itot_s(iValue, buffer, 3, 10) ;//将int转换成char*
    8. strValue.Format(_T("%s")) ;//将char*转换成CString
    9. strValue = strValue + _T("sec") ;//CString实现字符串相加
时间: 2024-08-24 20:23:59

常用的函数:atoi,itoa,atof,_ttoi等的相关文章

模拟实现库函数的atoi、atof和itoa

1.函数atoi atoi (表示 alphanumeric to integer)是把字符串转换成整型数的一个函数.广泛的应用在计算机程序和办公软件中.atoi( ) 函数会扫描参数 nptr字符串,跳过前面的空白字符(例如空格,tab缩进等). 原型:int atoi(const char *nptr),nptr:要进行转换的字符串: 功能:把字符串转换成整型数: 返回值:函数返回一个 int 值,此值由将输入字符作为数字解析而生成. 如果该输入无法转换为该类型的值,则atoi的返回值为 0

_itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明

原文:http://www.cnblogs.com/lidabo/archive/2012/07/10/2584706.html _itoa 功能:把一整数转换为字符串 用法:char * _itoa(int value, char *string, int radix); 详细解释: _itoa是英文integer to array(将int整型数转化为一个字符串,并将值保存在数组string中)的缩写.其中value为要转化的整数, radix是基数的意思,即先将value转化为radix进

转载 C++常用库函数atoi,itoa,strcpy,strcmp的实现

C++常用库函数atoi,itoa,strcpy,strcmp的实现 C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. 字符串转化为整数 - atoi4. 字符串求长 - strlen5. 字符串连接 - strcat6. 字符串比较 - strcmp7. 计算字符串中的元音字符个数8. 判断一个字符串是否是回文1. 写一个函数实现字符串反转 版本1 - while版 void strRev(char *s){    char temp, *end 

[c/c++] programming之路(23)、字符串(四)——strncat,atoi,strcmp,strlen等,以及常用内存函数

一.strncat及自行封装实现 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string.h> //<string.h>是C版本的头文件,包含比如strcpy.strcat之类的字符串处理函数. //<cstring>是C++版本的<string.h> //<string>定义了一个string的字符串类,包含

linux常用C函数目录

字符测试篇 isalnum isalpha isascii iscntrl isdigit isgraphis islower isprint isspace ispunct isupper isxdigit 字符串转换篇 atof atoi atol gcvt strtod strtol strtoul toascii tolower toupper 内存控制篇 calloc free getpagesize malloc mmap munmap 日期时间篇 asctime ctime get

嵌入式之---常用模板函数(用法说明函数、参数解析函数)

主要内容:嵌入式常用模板函数(用法说明函数.参数解析函数) /*显示参数列表*/ void usage() {     printf("usage: server [-p:x] [-i:IP] [-o]\n\n");     printf("       -p:x      Port number to listen on\n");     printf("       -i:str    Interface to listen on\n");

常用hash函数对比分析(一)

主要目标:寻找一个hash函数,高效的支持64位整数运算,使得在速度.空间等效率相对其它函数函数较高,以及内部运算时32位整数运算. 测试了"RSHash","JSHash","PJWHash","ELFHash","BKDRHash","SDBMHash","DJBHash","DEKHash","BPHash","

c/c++面试题(8)memcopy/memmove/atoi/itoa

1.memcpy函数的原型: void* memcpy(void* dest,cosnt void* src,size_t n); 返回值:返回dest; 功能:从源内存地址src拷贝n个字节到dest内存地址. 这里必须要求源地址的内存和目标地址的内存没有覆盖,如果有覆盖结果是未定义的. #include <stdio.h> #include <assert.h> void* my_memcpy(void* dest,const void* src,size_t n) { ass

sql常用格式化函数及字符串函数

一.常用格式化函数 1.日期转字符串 select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS') //2017-09-18 22:41:50 YYYY:年(4和更多位) MM:月份号(01-12) DD:一个月里的日(01-31) HH24:一天的小时数(00-23) MI:分钟(00-59) SS:秒(00-59) 2.字符串转日期 select to_date('2017-09-18','YYYY-MM-DD') //2017-09-

在PHP编程中常用的函数

<?php//===============================时间日期===============================//y返回年最后两位,Y年四位数,m月份数字,M月份英文.d月份几号数字,D星期几英文$date=date("Y-m-d");$date=date("Y-m-d H:i:s");//带时分秒 //include,include_once.require,require_once//require("file