16,472
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int main(void)
{
FILE* fp;
unsigned char a = 129;
fp = fopen("test.txt" , "wb");
fwrite(&a , sizeof(unsigned char) , 1 , fp);
fclose(fp);
fp = fopen("test.txt" , "rb");
fread(&a , sizeof(unsigned char) , 1 , fp);
fclose(fp);
printf("%d\n" , (int)a);
return 0;
}
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
FILE *fp;
long flen,bint[500],i;
fp = fopen("c:\\bsmain_runtime.log", "rb");
fseek(fp,0,SEEK_END);
flen=ftell(fp);
fseek(fp,0,SEEK_SET);
unsigned char *p,*s; //????????????,????0-255??ascii?
p=(unsigned char*)malloc((flen+1)*sizeof(unsigned char));
fread(p,1,flen,fp);
for(i=0;i <flen;i++)
{
printf("%x\t",*(p+i)); //??????
}
printf("\n\n");
for(i=0;i <flen;i++)
{
bint[i]= (long)(*(p+i));
printf("%d ",bint[i]);
}
}
char a, b, c;
a = 30;
b = 0x80;
c = 0x81;
CString str;
str.Format("a = %c, b = %c, c = %c", a, b, c);//以字符形式输出
afxMessageBox(str);
//这个时候你只会看到a b,c都是乱码。
但是你这样输出:
str.Format("a = %d, b = %d, c = %d", a, b, c);//以10进制整数输出
afxMessageBox(str);
//这个时候看到的就是a,b,c对应的值的10进制显示
str.Format("a = %x, b = %x, c = %x", a, b, c);//以16进制输出
afxMessageBox(str);
//这个时候看到的就是a,b,c对应的值的16进制显示