- 论坛徽章:
- 0
|
英文字母与汉字
我想这个可能对你有用:
- #include "i18n.h"
- #ifndef DEFAULTDEVICE
- #error DEFAULTDEVICE not set, check Makefile
- #endif
- #include <unistd.h>;
- #include <stdio.h>;
- #include <errno.h>;
- #include <sys/types.h>;
- #include <sys/stat.h>;
- #include <fcntl.h>;
- #include <stdlib.h>;
- int main(int argc, char *argv[])
- {
- int fd;
- int status;
- char *device;
- char buffer[33];
- I18NCODE
- if (argc == 2) {
- device = argv[1];
- } else if (argc == 1) {
- device = "/dev/" DEFAULTDEVICE;
- } else {
- fprintf(stderr, _("usage: volname [<device-file>;]\n"));
- exit(1);
- }
- fd = open(device, O_RDONLY);
- if (fd == -1) {
- perror(_("volname"));
- exit(1);
- }
- status = lseek(fd, 32808, SEEK_SET);
- if (status == -1) {
- perror(_("volname"));
- exit(1);
- }
- status = read(fd, buffer, 32);
- if (status == -1) {
- perror(_("volname"));
- exit(1);
- }
- printf("%32.32s\n", buffer);
- return 0;
- }
复制代码
它的头文件就是用来处理不同字符集的,可以用来读出汉字的光驱卷标:
- #ifndef __i18n__
- #define __i18n__
- #define PKG "eject"
- #define LOCALEDIR "/usr/share/locale"
- #include <locale.h>;
- #include <libintl.h>;
- #define _(str) gettext (str)
- #define N_(str) (str)
- #define I18NCODE setlocale(LC_ALL,""); textdomain(PKG); bindtextdomain(PKG,LOCALEDIR);
- void i18n_init (void);
- #endif
复制代码 |
|