社区
Linux/Unix社区
帖子详情
linux下wprintf为什么没有输出?
expert2000
2006-03-28 05:55:47
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
wchar_t* wstr=L"哈罗";;
setlocale(LC_CTYPE,"")
wprintf(L"%s\t",wstr);
return 0;
}
linux系统中的LANG= zh_CN.GB18030
redflag 4 个人版
输出为空,为什么?是不是系统要进行什么设置?
...全文
488
13
打赏
收藏
linux下wprintf为什么没有输出?
#include #include #include int main(void) { wchar_t* wstr=L"哈罗";; setlocale(LC_CTYPE,"") wprintf(L"%s\t",wstr); return 0; } linux系统中的LANG= zh_CN.GB18030 redflag 4 个人版 输出为空,为什么?是不是系统要进行什么设置?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
expert2000
2006-03-29
打赏
举报
回复
还有我输入的时候怎么好选择用什么编码。比如程序上面要球输入中文姓名。
expert2000
2006-03-29
打赏
举报
回复
为什么LANG=GB2312的时候,能输出UNICODE的哈罗,却输不出GB2312的哈罗。
当LANG=utf8时,反而输不出UNICODE的哈罗,输出的GB2312的哈罗也是鹿镁。
bcb_alone
2006-03-29
打赏
举报
回复
因为"哈罗"这两个字的编码,本身是GB2312.比如是 0x8400 0x8500
你是用GB2312中文输入法输入的。所以是GB2312.
而wchar是换成unicode的。
所以。用wprintf输出为unicode的字符。而unicode的0x8400对应的是另一个汉字。'鹿'
//这样是可以输出的。
lang = GB2312;
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
wchar_t a[3];
wchar_t* wstr=L"哈罗";
a[1] = 0x7F57; //unicode "哈"
a[0] = 0x54c8; //unicode "罗"
a[2] = L'\0';
setlocale(LC_CTYPE,"");
wprintf(L"%S\n",a);
return 0;
}
如果lang = utf8;
那么,当你重新打开你的C源文件时,“哈罗”两字已经变成其它字符了。
expert2000
2006-03-29
打赏
举报
回复
控制台输出,是不是编译的时候要加什么选项
expert2000
2006-03-29
打赏
举报
回复
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
wchar_t* wstr=L"哈罗";;
setlocale(LC_CTYPE,"")
wprintf(L"%s\t",wstr);//1
wprintf(L"哈罗\n");//2
return 0;
}
以上程序,注释掉第一个或者第二个wprntf都没有输出。2个同时存在,输出 鹿镁t@lo
把第一个和第二个wprintf中的\t,\n删掉。输出 鹿镁
用的命令 #LANG=zh_CN.utf8 ./appname
编译 : gcc -o appname appname.c
fierygnu
2006-03-29
打赏
举报
回复
试试执行
LANG=zn_CN.utf8 yourapp
expert2000
2006-03-29
打赏
举报
回复
输出一长串,有zn_CN.utf8等几十个.utf8
fierygnu
2006-03-29
打赏
举报
回复
系统环境能设置为utf8。locale -a看看。
expert2000
2006-03-29
打赏
举报
回复
注释掉后输出全是????
是不是系统的环境和我输出需要的环境不一致,要怎么设置?
expert2000
2006-03-29
打赏
举报
回复
十分感谢2位的回答。还有最后一点问题
其实上面的问题,要想读入任何码值都能正确显示,就是一个内码转换的问题。将读入的码和系统当前的码比较。不同就通过码值计算转换到相同。然后看码值在系统中是否有对应,有的话字符就能正确显示。
思路是不是这样?我听说unicode编码的字符在任何语言的操作系统中都能正确显示。这个unicode不是utf8吧?那是什么?linux支持unicode吗?
bcb_alone
2006-03-29
打赏
举报
回复
因为uft8和unicode和GB2312的编码是不同的。
expert2000
2006-03-29
打赏
举报
回复
已经可以输出了。假设输出语句还是2条。
wprintf(L"%s\t",wstr);//1
wprintf(L"哈罗\n");//2
输出情形如下:
[root@redflag c]#./app
[root@redflag c
[root@redflag c
[root@redflag c]#
这是结果不对,但是,我只要把窗口刷新一下,就对了。
[root@redflag c]#./app
哈罗
哈罗
[root@redflag c]#
这是为什么?我装入的是GB18030,GB2312,UTF8还是有问题。
fierygnu
2006-03-28
打赏
举报
回复
把setlocale(LC_CTYPE,"")注释掉试试。
浅谈C中的w
printf
和宽字符显示
浅谈C中的w
printf
和宽字符显示 非常值得收藏的一篇文档
解析w
printf
中使用%I64d格式化
输出
LONGLONG的详细介绍
w
printf
中使用%I64d格式化
输出
LONGLONG 在写某个程序时,因为需要用到一个大的整数,就是要了LONGLONG型: 代码如下:LONGLONG nLarge;但是格式化时不知道应该用什么字符,用 %d,%l都不行。LONGLONGLONGLONG其实就是int64类型。在winnt.h可以看到: 代码如下:typedef __int64 LONGLONG;所以要想
输出
就要看__int64使用什么格式符了。通过查MSDN中,发现是:I64。在格式化
输出
则还需要结合一个d,即%I64d。对于无符号的ULONGLONG,则是%I64u。例子 代码如下:LONGLONG nLarge
linux
C 学习资料
在
Linux
C编程中使用Unicode和UTF-8
Linux
C语言及
linux
知识
中文
输出
控制台乱码
中文
输出
控制台乱码
qt 通过hid获取指定usb设备 并读取数据
文件夹中包含hidapi.h hidapi.dll hidapi.lib,我是在windows10系统中用VS2013编译的release版本,我用于qt的调用,是可以实现的。 调用过程: int res; res = hid_init(); wchar_t wstr[MAX_STR]; int i; // Open the device using the VID, PID, // and optionally the Serial number. handle = hid_open(0x0483, 0x5750, NULL); if(handle == NULL) { qDebug() << "NULL-----------------------NULL" ; return; } else { qDebug() << " not ------------NULL-----------------------NULL" ; } // Read the Manufacturer String res = hid_get_manufacturer_string(handle, wstr, MAX_STR); w
printf
(L"Manufacturer String: %s\n", wstr); // Read the Product String res = hid_get_product_string(handle, wstr, MAX_STR); w
printf
(L"Product String: %s\n", wstr); // Read the Serial Number String res = hid_get_serial_number_string(handle, wstr, MAX_STR); w
printf
(L"Serial Number String: (%d) %s\n", wstr[0], wstr); // Read Indexed String 1 res = hid_get_indexed_string(handle, 1, wstr, MAX_STR); w
printf
(L"Indexed String 1: %s\n", wstr); qDebug("hid read start"); int res = hid_set_nonblocking(handle, 0); while (1) { res = hid_read(handle,buf,sizeof(buf)); QString asd ; for(int i = 0;i < sizeof(buf);i++) { char str[20]; s
printf
(str , "%02x",buf[i]); asd+=str ; } if(!cardInfo.contains(asd.toUpper())) { cardInfo.append(asd.toUpper() ); for(int i = 0;i < cardInfo.size() ;i++) { dealWithData( cardInfo[i]); } } }
Linux/Unix社区
23,217
社区成员
74,540
社区内容
发帖
与我相关
我的任务
Linux/Unix社区
Linux/Unix社区 应用程序开发区
复制链接
扫一扫
分享
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章