Overflow error in function

前端 未结 1 1483
眼角桃花
眼角桃花 2021-01-24 01:21

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

相关标签:
1条回答
  • 2021-01-24 01:23

    If you are taking the input from the user, then the code will be different.

    There are a few options,

    1. 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.

    2. 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");
    
    1. Loop for a fixed no of times, but your original code does not work that way and this will not be a good option for you.
    0 讨论(0)
提交回复
热议问题