Code:
int main(){
FILE *inputfile,*outputfile;
char temp[1000];
fgets(temp,1000,stdin); //get one-liner string from console and store it to temp
inputfile=tmpfile(); //open a temporary file
fputs(temp,inputfile); //copy the string in temp to fp
fflush(inputfile); //flush to solve stream buffering
outputfile=fopen("output.txt", "wt");
yyin=input;
yyout=output;
yylex();
floseall;
}
Actually, I'm working with LEX right now. I posted above the C language part of my program. Just don't bother with the yyin, yyout and yylex(), they're part of the LEX. So here is my problem:
I need to get a one-liner stdin input (meaning, the input will already be entered once you press enter). Then I need to copy that input to a file. Then that file is what I need for yyin, the input to yylex().
Here's how I approached the problem:
fgets(temp,1000,stdin);
First, I used fgets(). During some "experiments" i had done earlier, I confirmed that it was able to get all those inputed including the newline character.
inputfile=tmpfile();
Then I used tmpfile() to open a temporary file (well, we are not allowed to create a file on the physical space)
fputs(temp,input);
Then I used fputs. It seems this is where the problem started. For some reason, I can't have the inputfile contain what I inputed in the console. Otherwise, then yylex() would have been able to process the yyin.
I even used fflush. I've experimented with it a while ago, and the fflush there is working fine. It is not returning any error values.
Yeah this is LEX. But I'm only asking about the C language part. I'm just trying to have inputfile contain the string inputed in the console. Also, the inputfile should not create any file in the physical space. Anybody?