I have written a simple program to check the words of a text file is verb or not using flex. But I want to put (print) the output to a different text file.Is it possible? How will I do that?My sample code is:%%[\t]+is   |am   |are  |was  |were {printf(%s: is a verb,yytext);}[a-zA-Z]+ {printf(%s: is a verb,yytext);}. |\n%%int main(int argc, char *argv[]){        yyin = fopen(argv[1], r);        yylex();             fclose(yyin);}
How to put output to a different text file in flex
linux
I know not enough about lex/flex to be sure, but, given the code I see in the question, I'd try to add this code to main():FILE * myfd = fopen(argv[2], w);and use fprintf() instead of printf(), as in:{ fprintf(myfd, %s: is a verb, yytext); }I used argv[2] as source of the file name, which means you have to provide it as second argument in the program call, but you can also hard-code a string with a file name.