2012-11-12 2 views
0

12 자 및 정수를 입력 한 다음 사용자에게 다시 인쇄하도록 사용자에게 요청할 수 있습니다. 문자는 음표이고 정수는 초 단위의 각 음표 길이입니다. 여기 Arry에 사용자 입력을 저장하고 C로 사용자에게 다시 인쇄

내 코드입니다 :

//Include Standard IO 
#include <stdio.h> 
#include <string.h> 

//---------- 
//----------Main Function---------- 
//---------- 


int main() 
{ 

//Request Notes off of the user 
printf(" Please enter a musical sequence of 15 notes in capitals: "); 
printf("\n Please use the # character if needed"); 
printf("\n Please enter the time you want each note to last in seconds"); 


//Declare and initialize a table of notes as chars 
int notelist[12]; 
int*ptr; 
ptr = notelist; 
//Creating the array for the single notes 
char note[3]; 
//Creating a variable for the beginning of the note 
int start; 
//Declare and initialize a table of integers for the length of each note 
int notelength[20]; 
//Creating a variable for the length of the note 
int time; 
//Creating a variable for the loop so that it runs 15 times 
int loop; 


    //Creating a loop that will run 15 times for the 15 note values 
    for(loop=1; loop<4; loop++) 

    { 
     //Request a note off the user 
     printf("\n\n Please enter a note in capitals: "); 
     //Taking the input from the user 
     scanf("%s", note); 

     //Ask the user for the length he/she wants each note to be 
     printf("\n Please enter the length you want each note to be in seconds: "); 
     //Taking the input from the user 
     scanf("%d", &time); 
     notelength[time]=time+1; 
    } 

    //Print the input from the user back 
    for(start=1; start<4; start++) 
    { 
     scanf("%d", &*ptr++); 
    } 

    for(start=1; start<4; start++) 
    { 
     printf("%d", *ptr++); 
    } 


//Return 0 to let the OS know the program finished successfully 
return 0; 
} 

어떻게 사용자가 입력 한 12 노트와 길이를 저장하고 루프가 완료되면 그들에게 다시 인쇄 할 수 있습니까?

+2

무엇이 당신의 질문입니까? –

+0

루프가 끝나면 사용자가 입력 한 12 개의 노트와 길이를 저장하고 다시 인쇄 할 수 있습니까? – user1818845

답변

0

나중에 인쇄 할 수있는 모든 노트를 저장하려면 동적으로 할당 된 스택이 필요합니다. 모든 데이터 구조 서적이나 온라인 자습서가 도움이 될 것입니다.

관련 문제