In C the memory for strings has to be allocated explicitly. The following would work:
"while" {
printf("%s is a loop\n",yytext);
str = malloc(strlen(yytext)+1);
if (str == NULL) abort();
strcpy(str,yytext);
}
Beware that the above code will leak memory if the while
keyword occurs more than once in the input.