This is my code
strcpy doesnt copy the yytext
Any suggestion why?
These are my globals
char** v; /* array of variables and their values */
int i;
some name definition
WORD [a-zA-Z]
DIGIT [0-9]
These are the states
<VAL>"\"".+"\"" {int x=sizeof(yytext);
v[i]=(char*)realloc(v, x*sizeof(char));
strcpy(v[i],yytext);
i++;
BEGIN(INITIAL);}
<VAL>. { i--;printf("error");}
<SAVE_VAL>{WORD}[{WORD}{DIGIT}_]* {
if (NULL==v){
v=(char**)realloc(v, 100*sizeof(char*));
i=0;
}
int x=sizeof(yytext);
v[i]=(char*)realloc(v, x+2);
strcpy(v[i],yytext);
i++;
BEGIN(VAL);
}
val" " {BEGIN(SAVE_VAL);}
This is the yywrap
int yywrap(void){
return 1;
}
This is the main
int main(void) {
yyin=fopen("input.txt","r");
yylex();
fclose(yyin);
This is the loop to print the strings
for (int j=0;j<100;j++){
if (NULL==v[j])
break;
printf("%s",v[j],i);
}
}
}
I'm tring to run it on val a="asdasd";
I'm expecting it to print
a
asdasd