写正确函数需要注意的地方:int转char*, char* 转int。
来源:互联网 发布:网络电视排行 编辑:程序博客网 时间:2024/06/05 01:02
void invert(char* a, int start, int end){for(;start<end;++start,--end){char temp=a[start];a[start]=a[end];a[end]=temp;}}int toint(char *str){int result=0;for(int i=0;str[i]!=0;++i){result*=10;result+=str[i]-'0';}return result;}char* tochar(int it){char * temp=new char[1000];int mod=10;int left=it%mod;int size=it/mod;int i=0;while(size!=0 || left!=0){temp[i]=left+'0';it/=10;left=it%mod;size=it/mod;++i;}temp[i]=0;//注意最后补上终止符号0invert(temp, 0, i-1);return temp;}int _tmain(int argc, _TCHAR* argv[]){char str[1000];scanf("%s", str);int intresult=toint(str);printf("%d\n", intresult);char* strresult=tochar(intresult);printf("%s\n", strresult);delete []strresult;//注意是删除数组。return 0;}
1. 注意最后一个元素的赋值。也就是字符串结束标志的赋值。
2. delete []。注意删除动态开辟的内存区 。由于需要删除数组使用delete []strresult。
- 写正确函数需要注意的地方:int转char*, char* 转int。
- IP Int 转 Char
- int转char*
- char 转 int
- char转int
- int 逐个转 char
- char 数字转int
- char 转 int 型
- Char 转int JAVA
- iOS int 转 char
- char转int方法
- c++ int 转char * 函数 _itoa_s
- 写正确函数需要注意的地方:strstr
- 写正确函数需要注意的地方:二分查找
- 写正确函数需要注意的地方:快速排序
- 运行时输入的char转int
- 字符char转整形int的操作方法
- C++--char * 与int的互转
- android--->Linkify介绍
- Determining the Size of a Class Object
- ios 旋转屏幕横竖屏总结
- hdu 2795 线段树
- 《QTP自动化测试最佳实践》(第三版) 修订的内容
- 写正确函数需要注意的地方:int转char*, char* 转int。
- The ‘Microsoft.ACE.OLEDB.12.0′ provider is not registered on the local machine (zz)
- [self performSelector:@selector(fun:) withObject:obj afterDelay:2.0];方法是可以在未执行前终止的
- ogre地形
- 3个字节的空txt文本文件——utf8
- C/C++预处理指令
- bat运行java文件(含参数文件)
- Android通过JNI调用驱动程序(完全解析实例)
- web框架表现层,业务层,持久层的特点