什么是错我的功能或主? [英] Whats wrong with my function or main?

查看:135
本文介绍了什么是错我的功能或主?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有的code的工作我希望它除了我的播放功能的方式。
我试图使程序读取由记录功能创建的.txt文件,并弹奏音符回来。不幸的是,当用户presses P至播放他们已经记录的音符,它只是不断用相同的菜单弹出,而不是前进到程序的下一步。任何帮助高度AP preciated,它可能是一些小事情,但我一直在一整天的工作就可以了,并很努力了解决问题的自己。

 的#includeaservelibs / aservelib.h
#包括LT&;&stdio.h中GT;
#包括LT&;&math.h中GT;
#包括LT&;&string.h中GT;浮mtof(INT注,浮动频率);
文件播放(无效);
文件记录(无效);
FILE RECORD2(无效);诠释的main()
{
   FILE * textFilePointer;
   FILE * textFilePointer2;
   INT计数器= 0;
   字符的用户;   做
   {
      的printf(preSS A到记录1旋律(A),B为记录第二旋律(B)\\ NP演奏旋律(P):);
      scanf函数(%C,&安培;用户);      如果(用户=='一'||用户=='A')
      {
         textFilePointer = FOPEN(/用户/卢克/桌面/ midinotes1.txt,W);
         * textFilePointer =记录();
         计数器= 0;
      }      否则,如果(用户=='B'||用户=='B')
      {
         textFilePointer2 = FOPEN(/用户/卢克/桌面/ midinotes2.txt,W);
         * textFilePointer2 = RECORD2();
         计数器= 0;
      }      否则,如果(用户=='P'||用户=='P')
      {
         textFilePointer = FOPEN(/用户/卢克/桌面/ midinotes1.txt,R);
         textFilePointer2 = FOPEN(/用户/卢克/桌面/ midinotes2.txt,R);
         计数器= 0;
      }
   }
   而(计数器< 16);
}浮mtof(INT注,浮动频率)
{
   频率= 440.0 * POW(2,(注意-69)/ 12.0);
   的printf(%d个\\ N,注);
   返回频率;
}文件播放(无效)
{
   FILE *文件;
   文件= FOPEN(/用户/卢克/桌面/ midinotes1.txt,R);
   文件= FOPEN(/用户/卢克/桌面/ midinotes1.txt,R);   做{      INT注= aserveGetNote();
      INT速度= aserveGetVelocity();
      的fscanf(文件%D,%d个\\ n,&安培;请注意,&安培;速度);
      INT频率= mtof(注意,频率);
      aserveOscillator(0,频率,1.0,0);
      aserveSleep(500);
   }而(的feof(文件)== 0);   FCLOSE(文件);
   返回*文件;
}文件记录(无效)
{
   INT计数器;
   FILE *文件;
   文件= FOPEN(/用户/卢克/桌面/ midinotes1.txt,W);   做
   {      INT注= aserveGetNote();
      INT速度= aserveGetVelocity();
      如果(速度大于0)
      {
         fprintf中(文件%D,%d个\\ N,请注意,速度);
         反++;
      }
   }而(计数器< 16);
   FCLOSE(文件);
   返回*文件;
}FILE RECORD2(无效)
{
   INT计数器;
   FILE *文件;
   文件= FOPEN(/用户/卢克/桌面/ midinotes2.txt,W);   做
   {      INT注= aserveGetNote();
      INT速度= aserveGetVelocity();
      如果(速度大于0)
      {
         fprintf中(文件%D,%d个\\ N,请注意,速度);
         反++;
      }
   }而(计数器< 16);
   FCLOSE(文件);
   返回*文件;
}


解决方案

您永远不会调用播放功能为:

 否则,如果(用户=='P'||用户=='P')
{
   ...
   玩();
}

all of my code is working the way i want it to apart from my "play" function. I'm trying to make the program read the .txt files created by the "record" function and play the notes back. Unfortunately when the user presses P to play back the notes they have recorded, it just keeps popping up with the same menu and not advancing to the next step of the program. Any help highly appreciated, it may be something small but i have been working on it all day and am struggling to solve the problems myself anymore.

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

float mtof(int note, float frequency);
FILE play(void);
FILE record(void);
FILE record2(void);

int main()
{
   FILE *textFilePointer;
   FILE *textFilePointer2;
   int counter = 0;
   char user;

   do
   {
      printf("Press A to Record 1st Melody (A), B to Record 2nd Melody (B)\nP to Play Melodies (P):");
      scanf(" %c", &user);

      if (user == 'a' || user == 'A')
      {
         textFilePointer = fopen("/Users/Luke/Desktop/midinotes1.txt", "w");
         *textFilePointer = record();
         counter = 0;
      }

      else if (user == 'b' || user == 'B')
      {
         textFilePointer2 = fopen("/Users/Luke/Desktop/midinotes2.txt", "w");
         *textFilePointer2 = record2();
         counter = 0;
      }

      else if (user == 'p' || user == 'P')
      {
         textFilePointer = fopen("/Users/Luke/Desktop/midinotes1.txt", "r");
         textFilePointer2 = fopen("/Users/Luke/Desktop/midinotes2.txt", "r");
         counter = 0;
      }
   }
   while(counter < 16);
}

float mtof(int note, float frequency)
{
   frequency = 440.0 * pow(2, (note-69) / 12.0);
   printf("%d\n", note);
   return frequency;
}

FILE play(void)
{
   FILE*file;
   file = fopen("/Users/Luke/Desktop/midinotes1.txt", "r");
   file = fopen("/Users/Luke/Desktop/midinotes1.txt", "r");

   do {

      int note = aserveGetNote();
      int velocity = aserveGetVelocity();
      fscanf(file, "%d, %d\n", &note, &velocity);
      int frequency = mtof(note, frequency);
      aserveOscillator(0, frequency, 1.0, 0);
      aserveSleep(500);
   } while (feof(file) == 0);

   fclose(file);
   return *file;
}

FILE record(void)
{
   int counter;
   FILE*file;
   file = fopen("/Users/Luke/Desktop/midinotes1.txt", "w");

   do
   {

      int note = aserveGetNote();
      int velocity = aserveGetVelocity();
      if (velocity > 0)
      {
         fprintf(file, "%d, %d\n", note, velocity);
         counter++;
      }


   } while (counter < 16);
   fclose(file);
   return *file;
}

FILE record2(void)
{
   int counter;
   FILE*file;
   file = fopen("/Users/Luke/Desktop/midinotes2.txt", "w");

   do
   {

      int note = aserveGetNote();
      int velocity = aserveGetVelocity();
      if (velocity > 0)
      {
         fprintf(file, "%d, %d\n", note, velocity);
         counter++;
      }


   } while (counter < 16);
   fclose(file);
   return *file;
}

解决方案

You never call the play function as in:

else if (user == 'p' || user == 'P')
{
   ...
   play ();
}

这篇关于什么是错我的功能或主?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆