我的程序接受用户提供的数字来确定正在记录的序列的长度。我如何获取该数字并让它确定执行此循环的次数。 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/