把字符串转化为整数,atoi 想必这个大家哦度知道,但是linux下没有itoa

其实是有的,请看:sprintf

man sprintf

就会看到如下:

SYNOPSIS
#include <stdio.h>

int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);

#include <stdarg.h>

int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

snprintf(), vsnprintf():
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE ||
_POSIX_C_SOURCE >= 200112L;
or cc -std=c99

DESCRIPTION
The functions in the printf() family produce output according to a format as described
below. The functions printf() and vprintf() write output to stdout, the standard out‐
put stream; fprintf() and vfprintf() write output to the given output stream;
sprintf(), snprintf(), vsprintf() and vsnprintf() write to the character string str.

The functions snprintf() and vsnprintf() write at most size bytes (including the termi‐
nating null byte ('\0')) to str.

The functions vprintf(), vfprintf(), vsprintf(), vsnprintf() are equivalent to the
functions printf(), fprintf(), sprintf(), snprintf(), respectively, except that they
are called with a va_list instead of a variable number of arguments. These functions
do not call the va_end macro. Because they invoke the va_arg macro, the value of ap is
undefined after the call. See stdarg(3).

These eight functions write the output under the control of a format string that speci‐
fies how subsequent arguments (or arguments accessed via the variable-length argument
facilities of stdarg(3)) are converted for output.

C99 and POSIX.1-2001 specify that the results are undefined if a call to sprintf(),
snprintf(), vsprintf(), or vsnprintf() would cause copying to take place between
objects that overlap (e.g., if the target string array and one of the supplied input
arguments refer to the same buffer). See NOTES.

Return value
Upon successful return, these functions return the number of characters printed
(excluding the null byte used to end output to strings).

到这里一目了然,返回的是整数

char string[32] ;

int number = 0 ;

sprintf(string,"%d",number) ;

printf("%s\n",string) ;

转载于:https://www.cnblogs.com/ChenChangXiong/p/10883061.html

linux 下把整数转化为字符串相关推荐

  1. 整数转化成字符串; 字符串转换为整数

    整数转化成字符串: 字符串转换为整数 /*整数转化成字符串*/ char *IntToStr(int num, char str[]) {int i = 0, j = 0;char temp[100] ...

  2. c#中将整数转化为字符串_在C#中将字符串转换为字节数组

    c#中将整数转化为字符串 Prerequisite: How to declare and use byte[] in C#? 先决条件: 如何在C#中声明和使用byte []? C#中的字符串到字节 ...

  3. 谭浩强C++课后习题13——整数转化为字符串,求i平方和

    谭浩强C++课后习题13--整数转化为字符串,求i平方和 题目一:用递归法将一个整数n转化为字符串.例如,输入483,应输出字符串"483".n的位数不确定,可以是任意位数的整数. ...

  4. 编写itoa函数,该函数为itoi函数的逆函数。将一个整数转化为字符串的形式。

    itoa函数 功 能: 把一整数转换为十进制字符串 用 法: void my_itoa(int n, char s[]) 思路: 整数转化为十进制字符串,首先,需要整除(n/=10)求余(n%10), ...

  5. c++实现atoi()和itoa()函数(字符串和整数转化)

    (0) c++类型所占的字节和表示范围 c 语言里 类型转换那些事儿(补码 反码) 应届生面试准备之道 最值得学习阅读的10个C语言开源项目代码 一:起因 (1)字符串类型转化为整数型(Integer ...

  6. php 测试数据整数,PHP中将字符串转化为整数(int) intval() printf() 性能测试

    背景.概述 早在Sql注入横行的前几年,字符串转化为整数就已经被列为每个web程序必备的操作了.web程序将get或post来的id.整数等值强制经过转化函数转化为整数,过滤掉危险字符,尽可能降低系统 ...

  7. 字符串转换成整数 php,PHP字符串怎么转化为整数

    PHP转化为整数的实现方法:1.在要转换的变量之前加上用括号括起来的目标类型:2.使用PHP的内置函数intval进行变量的转换操作:3.利用sprintf的"%d"格式化指定的变 ...

  8. C语言-将数字转化为字符串

    整数转字符串 itoa():将整型值转换为字符串 参数说明: itoa(int num,char* str,int radix):将num中前radix个数字转化为字符串.

  9. 1.实现将整数转换成字符串

    将一个整数转换成字符串,拿到这个题目首先想到标准库里提供了哪些可用的函数. 如果是在window下编程,可以用系统库函数itoa实现该功能,itoa函数原型如下: char* itoa(int val ...

最新文章

  1. [BZOJ4766]文艺计算姬
  2. struts2之OGNL用法
  3. python 如何在linux进行调试
  4. Ubuntu update case the virtualbox crash
  5. 生成式模型和判别式模型(转)
  6. vector的求和用法accumulate
  7. 怎么批量在数字里加入网页_手把手教你爬取天堂网1920*1080大图片(批量下载)——理论篇
  8. 关于8086七种寻址方式的练习
  9. 介绍 Android 的 Camera 框架
  10. 计算机应用基础实验报告册,大学计算机应用基础实验报告册 - 2010版 - (1)
  11. golang net/http访问https
  12. 【STM32 + HAL库】倒立摆
  13. 机器码解除教程,逃离塔科夫机器码解除,彩虹6号机器码解除,dayz机器码解除,腐蚀rust机器码解除
  14. Gym - 101964E - Fishermen - (二分+区间更新)
  15. 桌面虚拟化传输协议之android spice及spice源码分析之server(1)
  16. applicationContext.xml的头文件
  17. warcraft 3 经典语句之月之女祭司(Priestess of the moon)
  18. 边缘检测的评价指标:PR曲线,OIS,ODS,AP的计算与代码实现
  19. [2018.10.25]高通QFIL刷机:高通sdm845_la2.0用QFIL软件meta_build和flat_build刷机
  20. 链路聚合的手工模式和LACP模式

热门文章

  1. 安装sphinx的php扩展,安装php扩展sphinx
  2. 安装mysql第三步卡死_Mysql 安装服务无法启动解决方案与使用的一般使用指令
  3. linux里netstat与ps,linux命令——ps和netstat
  4. 相等变为1 编号_JavaScript 中的 4 个相等比较算法的介绍
  5. 接口调用导致阻塞_RocketMQ与Dubbo之间线程之间如何阻塞和唤醒
  6. 开源 微软 语音识别_能用嘴,绝不动手!支持跨屏的语音输入法,它来了!
  7. 参与社团活动的意义_大学参加社团活动有意义吗?
  8. ctfshow-萌新-web5( 利用位运算符控制SQL获取网站敏感信息)
  9. jdk1.8 HashMap ConcurrentHashMap
  10. sql 拼接同列的值