计入数组并写入文本文件 xcode

Counting into an array and writing to text file xcode

您好,我正在尝试计算来自键盘的音符数据并将数据写入一个文本文件,该文件随后将被读出并作为音符播放。

我似乎只能将一行数字写入文本文件,非常感谢您的帮助。对不起,我的一些功能代码仍然包含在全局中。

    #define SEQ_NOTENUM 8
    #define SEQ_NUM 2
    //  structures //

    typedef struct
    {
         int notenumber;
         int velocity;
    }NoteData;

    typedef struct
    {
        float frequency;
        float amplitude;
    } OscData;

    // functions //

     float mtof(int note);


    // originally in main //

    OscData noteToOsc(NoteData note);
    int setcount, count;
    int currentset;
    OscData osc;

    int main()

    {
        int key, vel;
        NoteData sequence[SEQ_NUM][SEQ_NOTENUM];
        OscData noteToOsc(NoteData note);
        FILE* Sequence1;

        // START PROGRAM RECORD -- WRITE an IF/ELSE to run program -   
      dummy line atm//
        aserveGetVelocity();


        Sequence1 = fopen ("sequence1.txt", "w");

        if (Sequence1 == NULL)

         {
             printf("file Error\n");
         }

         else
          {
                    for(setcount = 0; setcount < SEQ_NUM; setcount++)
             {
                printf("--- Please enter sequence %d (%d notes)...\n",
    setcount, SEQ_NUM);



                count = 0;

                while(count < SEQ_NOTENUM)
                 {
                      key = aserveGetNote();
                      vel = aserveGetVelocity();

                    if(vel > 0)
                     {
                         sequence[setcount][count].notenumber = key;
                         sequence[setcount][count].velocity = vel;

                fprintf(Sequence1, "note %d - %d/%d\n", count, key,
     vel);
                count++;

            }

            fclose(Sequence1);
        }

        return 0;
    }

    }

代码的缩进乱七八糟,掩盖了 fclose(Sequence1) 仅通过一次内循环就关闭文件的事实。你可能想把它移到更远的地方。