Преглед изворни кода

fix: 修复了步进模式下stdin清理的bug

SongZihuan пре 3 година
родитељ
комит
7ab094b074
1 измењених фајлова са 3 додато и 1 уклоњено
  1. 3 1
      src/brainfuck.c

+ 3 - 1
src/brainfuck.c

@@ -410,9 +410,11 @@ static int runBrainFuck_(bf_byte *byte, bf_env *env) {
                 printf("(Type j to jump to the next point. Type g to ignore all point.)\n");
             printf("Enter:");
             switch ((ch = getc(stdin))) {
-                case 'n':
                 case '\n':
                 case EOF:
+                    ungetc(ch, stdin);  // 放回该符号, 在清理stdin的时候再读取出来
+                    // 没有break
+                case 'n':
                     printf("continue...\n");
                     goto BREAK_WHILE;  // 跳出while(1)循环
                 case 'm':