LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 709|回复: 3

发一个很丑的查五笔编码的程序!

[复制链接]
发表于 2003-12-24 21:36:46 | 显示全部楼层 |阅读模式
可以说是有点恶心的程序了!不过还可以查查五笔,
本不怕丑的决心放出来:  
假定是用fcitx 的那个wbx.mb文件,试了一下98的编码改了好多,都不懂打字了 :p ,
如果有需要大家把它弄得漂亮一些!


  1. #ifdef HAVE_CONFIG_H
  2. #include <config.h>
  3. #endif

  4. #include <stdio.h>
  5. #include <stdlib.h>


  6. void usage(void) {
  7.   printf("用法: 程序名 你要查的字或词\n");
  8. }

  9. int findword(const char *a, const char *b) {
  10.   int i, j;
  11.   int equal = 1;

  12.   j = strlen(a) - 2;

  13.   for (i = strlen(b) - 1; i >= 0; i--) {
  14.     if (b[i] != a[j]) {
  15.       equal = 0;
  16.       return equal;
  17.     }
  18.     j--;
  19.   }

  20.   if (a[j] < 0)
  21.     equal = 0;
  22.   return equal;
  23. }

  24. void findcode(const FILE *p, const char *word) {

  25.   char strline[64];
  26.   char *str;

  27.   rewind(p);

  28.   while (!feof(p)) {
  29.     fgets(strline, 64, p);

  30.     if (findword(strline, word))
  31.       puts(strline);

  32.   }
  33. }

  34. int main(int argc, char *argv[])
  35. {

  36.   char filename[]="/usr/share/fcitx/wbx.mb";
  37.   FILE *fp;
  38.   int i;

  39.   if (argc != 2) {
  40.     usage();
  41.     exit(0);
  42.   }

  43.   fp = fopen(filename, "r");
  44.   if (!fp) {
  45.     fprintf(stderr, "打开 wbx.mb 文件错误!\n");
  46.     exit(1);
  47.   }

  48.   findcode(fp, argv[1]);


  49.   return EXIT_SUCCESS;
  50. }

复制代码
发表于 2003-12-25 22:14:23 | 显示全部楼层
你是一个字节一个字节比较的?
 楼主| 发表于 2003-12-26 11:07:15 | 显示全部楼层
是呀!是一个字节是个字节比较的,
我原来想用函数strstr的结果发现

可以出很多不准的查询:
汉字是双字节:我对汉字编程了解太少了
123456 --> 三个汉字
本来我查12是对的。
可是23有时也正确!
没法,只好一个字节一个字节的比了
发表于 2003-12-27 21:23:04 | 显示全部楼层
谢谢,收下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表