I\'m new to C programming and I\'ve been writing a virtual computer program that takes input from STDIN , the inputs basically represents commands that task the Virtual computer
If you are taking the input from the user, then the code will be different.
There are a few options,
Keep the same code, but put a condition on the user to press Ctrl-Z
after entering all the data. This will only work if you are the only person entering the data, and is generally not workable.
After every loop, you can ask the user if he wants to enter more data. Then you can get the input as a y/n
and loop back if the user enters y
.
An example is below.
do
{
scanf("%d %79s %d",operationCode,s,operand));
// Other code here
printf("\n Do you want to enter another value (y/n) ");
scanf(" %c",&check);
} while(check != 'n");