/ * * Name: Identifier.c * Author: x-bit, at www.patching.net, allrights reserved. * Description: Enter a string of characters to determine whether the string is not a legitimate C language identifier. * Date: 09-05-2004 * Compile Environment: Win2K VC6 Under debug pass * / # include
INT IDENTF (CHAR * STR); INT ISKEY (CHAR * STR); int X_STRCMP (Char * Si, Char * Di);
INT main () {Char Buffer [256]; Printf ("Enter A String:"); Gets (Buffer); Identf (Buffer) PUTS ("Legal Identifier"); Else Puts ("Illegal Identity "); Returnography;}
/ ************************************************** ********************************** / INT IDENTF (Char * STR) {INT FLAG = 0; char * p = Str; / * Judgment first Has characters comply with * / if ((* str> = 'a' && * str <= 'z') || (* str> = 'a' && * str <= 'z') || * str == '_') {FLAG = 1; Str ;} / * Start traversal judgment from the second character * / while (* str && flag) {IF ((* str> = 'a' && * str <= 'z' ) || (* str> = 'a' && * str = 'z') || * Str == '_' || (* str> = '0' && * str <= '9')) { FLAG = 1; Str ;} else flag = 0;} / * Judgment is a keyword * / if (flag) Flag = iskey (p);
Return flag;} / *********************************************************************** *************************** / INT iskey (char * str) {char * keyword [] = {"Auto", "Break", "Case", "char" , "const", "continue", "default", "do", "double", "float", "float", "for", "goto", "IF", " INT "," long "," register "," return "," short "," sizeof "," static "," struct "," Switch "," Typedef "," union "," unsigned " , "Void", "volatile", "while"}; INT I, FLAG = 1; for (i = 0; i <32; i ) {if (x_strcmp (str, keyword [i]) == 0) { FLAG = 0; Break;}}
Return flag;} / **************************** String comparison function ************ ****************** I wrote a strcmp () * / int x_strcmp (white) {while (*) {while (*) {while (*) {while (* Si, Char * DI) {while Si && * di && * si == * di) {Si ; di ;}
Return * Si- * Di;}