汉字对应编码转化成整数

0

这个代码不因该是将“张三”按照汉字对应编码转化成整数然后再输出来吗
为什么每次执行完输出结果不一样

如果想实现将汉字组成的字符串转化为整数的话,只能这么写吗?(注释内)(用循环不算)

纯小白

#include<stdio.h>
#include<stdlib.h>

int main() {
	char name[64]="张三";
	printf("%d\n",(int)(name));
	return 0;
}
/*
#include<stdio.h>
#include<stdlib.h>

int main() {
	char name[64]="张三";
	printf("%d %d\n",name[0],name[1]);
	return 0;
}

*/


*/
ava
й

2023-9-19

0

中文转换为数字?  中文倒是可以转换为 Unicode 编码,也是数字组成:(摘自网络)

#include <iostream>
#include <string.h>
#include<stdio.h>
using namespace std;

int main() {
	string str = "张三";
	string unicodeStr;
	size_t length = strlen(str.c_str()) + 1;
	setlocale(LC_ALL, "");
	wchar_t wstr[100];
	size_t t;
	mbstowcs_s(&t, wstr, str.c_str(), length);
	char charUnicode[5];
	for (size_t i = 0; i < wcslen(wstr); i++)
	{
		memset(charUnicode, '\0', 5);
		sprintf_s(charUnicode, "%04x", wstr[i]);
		unicodeStr.append(charUnicode);
	}

	printf("%s", unicodeStr.c_str());

	return 0;
}

ava
xiongfj ◑◑

2023-10-4

技术讨论社区