练习5-16 增加选项-d(代表目录顺序)。该选项表明,只对字母、数字和空格进行比较。要保证该选项可以和-f组合在一起使用。 /* charcmp: return < 0 if s < t , 0 if s = t,>0 if s >t */ #difine FOLD 4 /*以option的第2位辨别是否存在可选参数f(无视大小写)*/ #difine DIR 8 /*以option的第3位辨别是否存在可选参数d(只对是字母数字和空格比较)*/ int charcmp(char *s,char *t) { char a,b; int fold = (option & FOLD)? 1 : 0; int dir = (option & DIR)? 1 : 0; do{ if(dir){ while(!isalnum(*s) && *s != ' ' && *s != '\0') s++; while(!isalnum(*t) && *t != ' ' && *t ! = '\0') t++; } a = (fold)? tolower(*s) : s; s++; b = (fold)? tolower(*t) : t; t++; if(a == b && a == '\0') return 0; }while(a == b); return a - b; }