title: Using Lex to count string occurrences, possible problems with makefile
body: <p>Currently trying to read a C program using the Lex utility, and display the line occurrences of all the words that aren't reserved C words. I'm running into a huge list of errors saying 'Multiple definition of yyin' 'yyout' 'yylex' 'yy_create_buffer', etc... </p>
  
  <p>I feel like there is a problem with my makefile currently, possibly in my code also.
  Any help appreciated!</p>
  
  <p>My Code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  char currentLines[20][80];
  char identifier[1000][80];
  void foundWord(char *, int);
  int numLine = 1;
  %}
  
  %s newStr
  %x BLOCK
  
  %%
  "/*"                        BEGIN(BLOCK);
  &lt;BLOCK&gt;[^*\n]*        
  &lt;BLOCK&gt;"*"+[^*/\n]*   
  &lt;BLOCK&gt;\n             ++numLine;
  &lt;BLOCK&gt;"*"+"/"        BEGIN(INITIAL);
  
  "\n"                              ++numLine;
  
  auto                        ;
  break                       ;
  case                        ; //full list of reserved words...
  
  [*]?[a-zA-Z][a-zA-Z0-9_]*   foundWord(yytext, numLine);
  [^a-zA-Z0-9_]+              ;
  [0-9]+                      ;
  %%
  
  void foundWord(char* newStr, int nLine)
  {
  char num[10];
  sprintf (newStr, "%d", nLine);
  
  int i;
  for(i = 0; i &lt;= 20; i++)
  {
      if ( strcmp(identifier[i], newStr) == 0 )
      {
          strcat( currentLines[i], ", " );
          strcat( currentLines[i], num );
          return;
      }
  }
  
  strcpy( identifier[i], newStr );
  strcat( identifier[i], ": " );
  strcpy( currentLines[i], num );
  }
  </code></pre>
  
  <p>And here is the makefile I have written, attempting to link 'C_words.l' with the lex library. </p>
  
  <pre><code>C_words.exe : C_words.o lex.yy.o
      gcc -g -o C_words.exe C_words.o lex.yy.c -ll
  lex.yy.o : lex.yy.c
      gcc -g -c lex.yy.c
  lex.yy.c : C_words.l
      lex C_words.l
  </code></pre>
  
  <p>This is the input file I would like to use. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void main()
  {
      int m,n;
  
  printf("Enter the values for  M and N\n");
  scanf("%d %d", &amp;m,&amp;n);
  
  if(m == n )
      printf("M and  N are equal\n");
  else
      printf("M and N are not equal\n");
  
  }
  </code></pre>