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

时间:2015-03-23 20:17:53

标签: c xcode multidimensional-array count file-writing

您好我正在尝试从键盘输入音符数据并将数据写入文本文件,随后将其作为音符读出并播放。

我似乎只能在文本文件中写一行数字,并且非常感谢帮助。对不起,我还有一些功能代码包含在全球范围内。

    #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;
    }

    }

1 个答案:

答案 0 :(得分:0)

代码的缩进混乱了,模糊了fclose(Sequence1)仅在一次通过内循环后关闭文件的事实。你可能想把它移到更远的地方。