c - 根据用户的输入结束循环

标签 c function loops midi

我的程序接受用户提供的数字来确定正在记录的序列的长度。我如何获取该数字并让它确定执行此循环的次数。 while(true) 显然根本不允许循环结束。

提前致谢

这是从 MIDI 输入合成声音的函数

void midisound (int note)
    {
        int velocity;
        int playingNote = -1;
        float frequency;

        while(true)
        {
            note = aserveGetNote();
            velocity = aserveGetVelocity();

            if(velocity > 0)
            {
                frequency = 440 * pow(2, (note-69) / 12.0);
                aserveOscillator(0, frequency, 1.0, 0);
                playingNote = note;
            }
            else if(note == playingNote)
            {
                aserveOscillator(0, 0, 0, 0);
            }

        }


    }

---here is where function ^ is called in the program----

   if (reclayer == 1)
                    {
                        //open first text file for layer 1 to be written to
                        textFilePointer = fopen("recording1.txt", "w+");
                        if(textFilePointer == NULL)
                        {
                            printf("Error Opening File!");
                        }
                        else
                        {

                            //function call to write notes and vel data
                            notetofile(input, seqlen, reclayer);
                            printf("Would you like to record a second layer or re-record? (y or n)\n");
                            scanf(" %c", &choice2);
                        }

                    }

最佳答案

使用 for 循环。

for ( i = 0; i < note; i++ ) {
    // Your code here
}

这将执行“note”多次。

关于c - 根据用户的输入结束循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29271371/

相关文章:

c - 这个特定函数的时间复杂度\big(O) 是多少?

c - SetConsoleCursorPosition : Getting black rows in console upon use

c# - 在 C# 中定义可以接受大量参数的函数

php - 从另一个类 PHP 调用函数中的函数

c++ - 函数中的链接器错误

c - 从 C 中的数组中查找最大值和最小值

无法从另一个文件中的函数创建线程

c - 如何将 LTO 与符号版本控制相结合

c - C 中 openMP 的线程数问题

javascript - 无限循环不起作用