c-计数到一个数组中并写入文本文件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 Errorn");
         }
         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/%dn", count, key,
     vel);
                count++;
            }
            fclose(Sequence1);
        }
        return 0;
    }
    }

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

最新更新