ユーザーに 12 文字と整数を入力してもらい、それをユーザーに出力できるようにしたいと考えています。文字は音符で、整数は各音符の長さ (秒単位) です。
これが私のコードです:
//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 の音符と長さを保存し、ループが終了したときにそれを印刷するにはどうすればよいですか?