title: a given string is valid identifier or keyword in c++
body: <p>This is a code of checking a given string is an <code>identifier</code> or a <code>keyword</code>. Here is the code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;ctype.h&gt;
  
  
  int main(){
  
      int i = 0, flag = 0;
      char a[10][10] = {"int", "float", "break", "long", "char", "for", "if", "switch", "else", "while"}, string[10];
  
      //clrscr();
  
      printf("Enter a string :");
      gets(string);
  
      /*----Checking whether the string is in array a[][]----*/
  
      for(i = 0 ; i &lt; 10; i++){
          if( (strcmp( a[i], string) == 0) )
              flag = 1;
      }
  
      /*----If it is in the array then it is a keyword----*/
  
      if( flag == 1)
          printf("\n%s is a keyword ", string);
  
      /*----Otherwise check whether the string is an identifier----*/
      else{
          flag = 0;
          /*----Checking the 1st character*----*/
  
          if( (string[0] == '_') || ( isalpha(string[0]) != 0 ) ){
              /*---Checking rest of the characters*---*/
              for(i = 1; string[i] != '\0'; i++)
              if( (isalnum(string[i]) == 0 ) &amp;&amp; (string[i]!='_') )
                  flag = 1;
          }
          else
              flag = 1;
          if( flag == 0)
              printf("\n%s is an identifier ", string);
          else
              printf("\n%s is neither a keyword nor an identifier ", string);
      }
          getch();
  }
  </code></pre>
  
  <ul>
  <li>I want to do this code more easily. And is it possible to get or identified the 
  all keywords without declaring in the char? And how to do that?</li>
  </ul>
  
  <p>Can S.O provide me that code?</p>