程序中需要用到将整型转化为char*类型,然后将两个char*类型的变量拼接。将整型转化为char*自然想到了itoa函数:
头文件:#include
char *itoa(int value, char *string, int radix);
int value 被转换的整数,char *string 转换后储存的字符数组,int radix 转换进制数
但是在linux下,itoa函数没有定义,所以使用sprintf函数代替。
#include
#include"Hash.h"
using namespace std;
int main()
{
hash_table *hid;
char * key = new char[100];
char * tmp = new char[5];
strcpy(key, "hello-");
hid = hash_create();
hash_link link[5];
for(int j=0; j<5; j++)
{
link[j].next = NULL;
sprintf(tmp,"%d",j); //将整型转化为char*
strcat(key,tmp); //将两个char*字符串拼接,结果保存在第一个参数中
link[j].key = key;
hash_join(hid, &link[j]);
}
return 0;
}
Linux下c++中的atoi、atol、atoll、atof函数调用实例
本文中调用的四个函数如下: atoi函数:将字符串转化为int类型变量 atol函数:将字符串转化为long类型变量 atoll函数:将字符串转化为long long类型变量 atof函数:将字符串转 ...
Linux下函数调用堆栈帧的详细解释【转】