I want to build an online interactive shell that runs c programming but as soon I put scanf in my code it just ignores all the code until I give it all the inputs at first and then it gives me buffered code at once.
Here is my code:
childProcess = cp.spawn("/output.out")
childProcess.stdout.on("data", (data) => {
io.to(clientId).emit("result", data.toString() + "\n")
})
childProcess.on("data", (data) => {
io.to(clientId).emit("result", data.toString())
})
childProcess.on("error", (err) => {
io.to(clientId).emit("result", err.message.toString())
})
#include <stdio.h>
int main()
{
float num1;
double num2;
printf("Enter a number: ");
scanf("%f", &num1);
printf("Enter another number: ");
scanf("%lf", &num2);
printf("num1 = %f\n", num1);
printf("num2 = %lf", num2);
return 0;
}
The output (it's waiting for me to give the input at first then it runs the code)
5
5
Enter a number: Enter another number: num1 = 5.000000
num2 = 5.000000
The expected output should be
Enter a number: 5
Enter another number: 5
num1 = 5.000000
num2 = 5.000000
Is there a way around this?