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個音符和長度由用戶輸入並在循環結束後打印回給他們?
你的問題是什麼? –
如何儲存用戶輸入的12個音符和長度,並在循環結束時將其打印回給他們? – user1818845