免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 860 | 回复: 1
打印 上一主题 下一主题

英文字母与汉字 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-10-24 09:37 |只看该作者 |倒序浏览
有没有办法从一个文件中单独读出一个字符,而不用理会它是英文字母,还是汉字?
如果没有办法,那么应该怎样单独读出一个汉字?

论坛徽章:
0
2 [报告]
发表于 2004-10-25 09:42 |只看该作者

英文字母与汉字

我想这个可能对你有用:
  1. #include "i18n.h"

  2. #ifndef DEFAULTDEVICE
  3. #error DEFAULTDEVICE not set, check Makefile
  4. #endif

  5. #include <unistd.h>;
  6. #include <stdio.h>;
  7. #include <errno.h>;
  8. #include <sys/types.h>;
  9. #include <sys/stat.h>;
  10. #include <fcntl.h>;
  11. #include <stdlib.h>;

  12. int main(int argc, char *argv[])
  13. {
  14.   int fd;
  15.   int status;
  16.   char *device;
  17.   char buffer[33];

  18.   I18NCODE

  19.   if (argc == 2) {
  20.     device = argv[1];
  21.   } else if (argc == 1) {
  22.     device = "/dev/" DEFAULTDEVICE;
  23.   } else {
  24.     fprintf(stderr, _("usage: volname [<device-file>;]\n"));
  25.     exit(1);
  26.   }

  27.   fd = open(device, O_RDONLY);
  28.   if (fd == -1) {
  29.     perror(_("volname"));
  30.     exit(1);
  31.   }

  32.   status = lseek(fd, 32808, SEEK_SET);
  33.   if (status == -1) {
  34.     perror(_("volname"));
  35.     exit(1);
  36.   }

  37.   status = read(fd, buffer, 32);
  38.   if (status == -1) {
  39.     perror(_("volname"));
  40.     exit(1);
  41.   }

  42.   printf("%32.32s\n", buffer);

  43.   return 0;
  44. }
复制代码


它的头文件就是用来处理不同字符集的,可以用来读出汉字的光驱卷标:
  1. #ifndef __i18n__
  2.    #define __i18n__
  3.    #define PKG "eject"
  4.    #define LOCALEDIR "/usr/share/locale"

  5.    #include <locale.h>;
  6.    #include <libintl.h>;
  7.    #define _(str) gettext (str)
  8.    #define N_(str) (str)
  9.    #define I18NCODE setlocale(LC_ALL,""); textdomain(PKG); bindtextdomain(PKG,LOCALEDIR);

  10.    void i18n_init (void);
  11. #endif
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP