fprintf(textFilepointer) 在文件中打印两次
fprintf(textFilepointer) print twice into file
#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;
}
#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;
}