整数转字符串
来源:互联网 发布:sql 给字段设置默认值 编辑:程序博客网 时间:2024/05/22 13:22
将输入的整数转化为字符串。输入:整数 。输出:指向字符串的指针
函数原型:char *shuzi2zifu(int n)
#include<stdio.h>#include<string.h>#include<stdlib.h>char *shuzi2zifu(int n){char *p;int count=0;int i=0;int temp;int flag;if(n<0){flag=1;n=-n;}else flag=0;int m=n;while(n){n=n/10;count++;}printf("%d\n",count);p=(char *)malloc(sizeof(char)*count);n=m;while(n){p[i++]=n%10+'0';n=n/10;}if(flag==1){p[i++]='-';count++;}p[i]='\0';for(int j=0;j<count/2;j++){temp=p[j];p[j]=p[count-1-j];p[count-1-j]=temp;}return p;}void main(){char *p;int n;printf("please input the data:");scanf("%d",&n);p=shuzi2zifu(n);puts(p);}
运行结果:
please input the data:349730
6
349730
please input the data:-7862
4
-7862
- 字符串处理------字符串转整数
- 数字字符串转整数
- 整数转字符串
- 字符串转整数
- 字符串转整数
- 字符串转整数
- 字符串转整数
- 字符串转整数
- 20. 字符串转整数
- 字符串转整数
- 字符串转整数
- CSDN-字符串转整数
- 整数转字符串
- c字符串转整数
- 字符串转整数问题
- 字符串转整数(C#)
- c 整数转字符串
- 字符串 转整数
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B_Eliminate Witches!
- va_start和va_end的用法
- 香农定理 奈奎斯特定理 傅立叶变换 z变换 S变换
- GCC使用手册及常用命令行
- HDU 4046 Panda 树状数组
- 整数转字符串
- 全球经典IT争霸战启示录:请尊重你的对手
- gstreamer使用进阶
- 快捷键
- 工厂方法
- Linux网络编程中的地址问题
- Linux中gcc,g++常用编译选项以及makefile的编写
- Zoj 2599 (数位dp,数位统计)
- java笔记1