How to fix a warning message associated with strlen() used in Yacc?
- by user547894
Hello! Please i need your help. Basically, I am facing this warning message upon compiling with gcc, and am not able to deduce the error:
Here are the details:
The warning message i am receiving is literrally as follows:
y.tab.c: In function ‘yyparse’: y.tab.c:1317
warning: incompatible implicit declaration of built-in function ‘strlen’
My Lex File looks like:
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "y.tab.h"
void yyerror(const char*);
char *ptrStr;
%}
%START nameState
%%
"Name:" { BEGIN nameState; }
<nameState>.+ {
ptrStr = (char *)calloc(strlen(yytext)+1, sizeof(char));
strcpy(ptrStr, yytext);
yylval.sValue = ptrStr;
return sText;
}
%%
int main(int argc, char *argv[])
{
if ( argc < 3 )
{
printf("Two args are needed: input and output");
}
else
{
yyin = fopen(argv[1], "r");
yyout = fopen(argv[2], "w");
yyparse();
fclose(yyin);
fclose(yyout);
}
return 0;
}
My Yacc file is as follows:
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "y.tab.h"
void yyerror(const char*);
int yywrap();
extern FILE *yyout;
%}
%union
{
int iValue;
char* sValue;
};
%token <sValue> sText
%token nameToken
%%
StartName: /* for empty */
| sName
;
sName:
sText
{
fprintf(yyout, "The Name is: %s", $1);
fprintf(yyout, "The Length of the Name is: %d", strlen($1));
}
;
%%
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
*I was wondering how to remove this warning message. Please any suggestions are highly appreciated!
Thanks in advance.