You can't do that in the C version of 'flex', as yytext
points directly into the input buffer. It isn't a copy. If you modify the input buffer you will screw things up royally. flex takes extreme care to process each character once and only once, and it doesn't do any extra buffering of its own beyond whatever the source you provide to it does. I believe it temporarily puts a NUL into the buffer while executing an action, and takes it out again when the action returns, for which purpose it must therefore have a pointer to where the NUL was.
I would move that processing into the grammar at the appropriate points, where you must already be taking a copy of yytext.