c - “notestofile”功能不起作用

标签 c xcode function

#include "aservelibs/aservelib.h"
#include <stdio.h>
#include <math.h>
#include <string.h>

FILE *textFilePointer;


void notetofile ();

int main()
{

    int count, count2, note, vel = 0;
    char choice = 'y';

    printf("Welcome To Jonny Maguire's Midi record and playback application. Please Select one of the following options...\n\n");
    aserveSay("Welcome To Jonny Maguires Midi record and playback application. Please Select one of the following options");
    aserveSleep(8000);
    while(choice != 'x')
    {
        for(count = 0; count <=2;)
        {

            printf("r to Record\np to Playback\nx to exit the program\n");
            aserveSay("choose r, to record a sequence, p, to playback your recording. Or select x, at any time to exit the program");

            scanf(" %c", &choice);

            if(choice =='r')
            {
                aserveSay("you have chosen to record, play any 16 notes on the midi keyboard");
                printf("You have chosen to record, please play 16 notes on the midi keyboard\n\n");

                textFilePointer = fopen("recording1.txt", "w");

                if(textFilePointer == NULL)
                {
                    printf("Error Opening File!");
                }
                else
                {
                    for(count2 = 1; count2 <=2; count2++)
                    {
                        //Recording 16 note data into txt file
                        notetofile();
                    }
                }
            }
            //If P is selected, playback of the txt file
            else if (choice == 'p')
            {
                textFilePointer = fopen("recording1.txt", "r");

                if(textFilePointer == NULL)
                {
                    printf("Error Opening File!");
                }

                //read until end of file and convert frequency
                while(!feof(textFilePointer))
                {
                    float frequency;
                    float amplitude = vel/127.0;

                    fscanf(textFilePointer, " %d %d\n", &note, &vel);
                    printf(" %d %d\n\n", note, vel);

                    frequency = 440 * pow(2, (note-69) /12.0);

                    aserveOscillator(0, frequency, amplitude, 0);
                    aserveSleep(500);
                    aserveOscillator(0, 0, 0, 0);
                }
            }
            fclose(textFilePointer);
        }
    }

    return 0;
}

void notestofile (int count, int count2, int note, int vel)
{
    //Recording 16 note data into txt file
    for (count = 1; count <= 16;)
    {


        note = aserveGetNote();
        vel = aserveGetVelocity();


        //only note on messages are sent to file
        if(vel > 0)
        {
            fprintf(textFilePointer, " %d %d\n", note, vel);
            printf("%d %d\n", note, vel);
            count++;
        }
    }
}

我试图放入 main 中的名为“notestofile”的函数给了我错误“Apple Mach-O Linker (id) error”并且不会让我构建。该函数应该将音符编号写入文本文件,并在其位于 main 中而不是通过函数传递时起作用。预先感谢:)

最佳答案

您声明并调用 notetofile(),但定义 notestofile()。删除(或添加?)s 以修复错误。您还使用非原型(prototype)声明并在不带任何参数的情况下调用它。使用原型(prototype)可以防止这种情况发生,因此请进行更改

void notetofile ();

void notetofile(int count, int count2, int note, int vel);

关于c - “notestofile”功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29195230/

相关文章:

c 指针,如何将它/它们释放到一个函数中

javascript - JavaScript 中基于范围的变量阴影

c - free() 使用不同的指针释放相同的堆内存

c++ - 关于加密歌曲

r - 自 Xcode 命令行工具更新以来无法安装 stringi

iOS 解析聊天应用程序 : Updating data from multiple pushes while in background/inactive.

C++ (C++11) 中的函数对象

c - 在 C 中读入带空格的字符串

c - 处理错误 - C 中结构之前的预期表达式

ios - 缺少[在开始消息中发送表达式