#include "aservelibs/aservelib.h"
#include <stdio.h>
#include <math.h>
FILE *textFilePointer;
int main()
{
int counter = 0;
int note;
printf("Press key on Axiom MIDI keyboard to display note number\n");
textFilePointer = fopen("/Users/jonnymaguire/Documents/Uni Work/Audio Programming /iap/iapProj/Builds/MacOSX/build/Debug/textp15.txt", "w");
do
{
if(textFilePointer == NULL)
{
printf("!Error Opening File!");
}
else
{
/*get frequency from user*/
note = aserveGetNote();
fprintf(textFilePointer, "note = %d\n", note);
fprintf(textFilePointer, "hex note = %x\n\n", note);
counter++;
}
}
while(counter < 16);
fclose(textFilePointer);
return 0; /*end*/
}
这个程序只是简单地将音符编号打印到文件中,一旦它们被用户在键盘上弹奏。然而,它打印所有东西的两倍,所以我不能记录 15 个不同的音符编号和十六进制音符编号,因为它每次都写双倍。为什么?
最佳答案
如果您在播放每个音符时收到两条消息,一条是按键,一条是按键释放,您可以通过将音符消息打印到控制台来判断这一点,而不是的到一个文件。试试这个:
#include "aservelibs/aservelib.h"
#include <stdio.h>
#include <math.h>
int main(void) {
int counter = 0;
int note;
printf("Press key on Axiom MIDI keyboard to display note number\n");
do
{
/*get frequency from user*/
note = aserveGetNote();
printf("note = %d\n", note);
counter++;
}
while(counter < 16);
return 0;
}
关于c - fprintf(textFilepointer) 在文件中打印两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28966266/