2014-12-03 5 views
0

내 char 읽기 기능이 작동하지 않는다. 인쇄하고 싶은 것이 인쇄되지만 프로그램이 다음 단계로 넘어 가지 않고 사용자가 입력 한 숫자를 읽지 못하게한다. 이 당신은 읽기의 응답을 반환해야 할당내 기능에 문제가 있습니까?

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

int length(); 
float mtof(int note); 
float octave(int notes); 
char read(char print); 


int main() 
{ 
    //do while the user hasnt pressed exit key (whatever) 
    int control[8] = {74, 71, 91, 93, 73, 72, 5, 84}; 
    int index; 
    int mod; 
    float frequency; 
    int notes[8]; 
    int response; 
    float octave; 
    char print; 

    mod = aserveGetControl(1); 




    //ask backwards, forwards, exit 

    //SCALING 
    //(getControl(75)/((127 - 0)/(1000 - 100))) + 100; 
    while(true) 
    { 
     read(print); 
     mod = 0; 
     if(response == 1) 

     { 
      while(mod==0) 
      { 
       for(index = 0; index < 8; index++) 
       { 
        notes[index] = aserveGetControl(control[index]); 
        frequency = mtof(notes[index]); 
        aserveOscillator(0, frequency, 1.0, 0); 
        aserveSleep(length()); 
        printf("Slider Value:%5d\n", notes[index]); 
        printf("frequency: %f\n", frequency); 
        mod = aserveGetControl(1); 
        octave = aserveGetControl(7); 
       } 
      } 
     } 
     else if(response == 2) 
     { 
      while(mod==0) 
      { 
       for(index = 7; index > 0; index--) 
       { 
        notes[index] = aserveGetControl(control[index]); 
        frequency = mtof(notes[index]); 
        aserveOscillator(0, frequency, 1.0, 0); 
        aserveSleep(length()); 
        printf("Slider Value:%5d\n", notes[index]); 
        printf("%f", frequency); 
        mod = aserveGetControl(1); 

       } 
      } 

     } 
     else if(response == 0) 
     { 
      return 0; 
     } 
    } 

} 
int length() 
{ 
    return (aserveGetControl(75)/((127.0 - 0)/(1000 - 100))) + 100; 
} 

float mtof(int note) 
{ 
    return 440 * pow(2, (note-69)/12.0); 
} 
float octave(int note) 
{ 
    float slider = aserveGetControl(7)/16383.0; 
    slider *=24; 
    return 440 * pow(2, ((note+slider)-69)/12.0); 
} 
char read(char print) 
{ 
    char response; 
    printf("Run Loop Forwards (1), Backwards (2), Exit (0)\nMove modwheel to return to menu\n"); 
    scanf("%c", &response); 
} 

답변

0

입니다 같은 기능의 일정 금액을 가지고 :

char read(char print) 
{ 
    char response; 
    printf("Run Loop Forwards (1), Backwards (2), Exit (0)\nMove modwheel to return to menu\n"); 
    scanf("%c", &response); 
    return response; 
} 

을 당신은 당신의 코드의 주요 경로에 할당해야합니다

response = read(print); 

필자는 실제로 응답을 char로 선언해야한다는 것을 지적하고자한다. 또한 어디에서나 사용되는 인쇄물을 볼 수 없으므로 읽을 때 전달할 목적이 확실치 않습니다.

관련 문제