转换unsigned int类型为char字母 [英] convert unsigned int to char alphabets
问题描述
我有以下的code可以转换的流数据的 16位整数的到的 8位无符号整数的。结果
我期待它们转换英文字母的数据值,看看它们包含的内容。
I have the following code that converts a stream data of 16-bit integer to unsigned 8-bit integer.
I am looking to convert them to alphabetical data values and see what they contain.
#include<stdio.h>
int main() {
FILE *fp,*out;
char buffer[256];
size_t i = 0;
fp=fopen("c:/Gosam/input.txt", "rb");
if(fp != NULL) {
fread(buffer, sizeof buffer,1, fp);
}
out = fopen("c:/Gosam/res.txt", "w");
if(out != NULL) {
// buffer = (char*) malloc (sizeof(char)*Size);
for( i = 0; i < sizeof(buffer); i += 2)
{
const unsigned int var = buffer[i] + 256 * buffer[i + 1];
fprintf(out, "%u\n", var);
}
fclose(out);
}
fclose(fp);
}
下面是我的输出形式为:
The following is the form of my output:
263 4294966987 4294967222 4294967032 64 4294967013 73 4294967004 90
4294967028 83 4294966975 37 4294966961 5 4294966976 82 4294966942
4294967022 4294966994 11 4294967024 29 4294966985 4294966986 4294966954 50
4294966993 4294966974 4294967019 4294967007
这是我要转换为英文字母,看看他们的内容价值。
This are the values I want to convert to alphabetical characters and see their content.
推荐答案
我不知道您的期望作为一个答案(你没有问一个问题),但似乎是在$一个系统一台可疑的东西$ C:
I don't know what you expect as an answer (you didn't ask a question), but there seems to be one suspicious thing in your code:
char buffer[256];
下面字符
办法符号字符
。如果你的code确实对他们的操作(如256倍),它可能不会做你期望的(虽然我只能猜测你所期望的 - 你的问题没有提到它)。
Here char
means signed char
. If your code does manipulations on them (like multiplying by 256), it probably doesn't do what you expect (though I can only guess what you expect - your question doesn't mention it).
请尝试以下操作:
unsigned char buffer[256];
另外,请问一个问题(即带问号的东西),并给出一些例子(输入,输出)。
Also please ask a question (that is, something with a question mark), and give some examples (input, output).
这篇关于转换unsigned int类型为char字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!