私は C に不慣れで、正直なところ、構造体の配列から特定の要素を削除することをどこから始めればよいかわかりません。
必要に応じて、ここで私のコード全体を表示およびコピーできます: http://pastebin.com/Zbrm2xyL
ほとんどの場合、関数「rmv_student」に関心があります。これは、ユーザーに確認を求めた後、その配列の他の要素をいじることなく、配列「st_array」から一致する ID 番号を持つ構造体を削除することになっています。関数「rmv_student」は次のとおりです。
void rmv_student(long id) // BROKEN
{
int i; // iterator
char response; // used to confirm deletion
for( i = 0; i < MAX; i++){
if ( st_array[i].id == id){
printf("Are you sure you want to delete %s %s, %d?\n", st_array[i].first_name, st_array[i].last_name, st_array[i].id);
puts("You will not be able to undo the deletion.");
puts("Enter 'y' to delete or 'n' to return to the main menu.");
response = getchar();
switch (response){
case 'y':
// delete
case 'Y':
// delete
case 'n':
main();
case 'N':
main();
default:
puts("Please enter 'y' or 'n'.");
rmv_student(id);
}
}
}
if ( i == MAX ){
printf("\nThere are no students with ID %d.\n\n", id);
main();
}
}
2 つの質問があります。
私のスイッチケースは正しいですか?これはユーザーの入力文字を正しくテストしますか?
構造体を削除するにはどうすればよいですか?
あなたが尋ねる前に。はい、これは宿題です。そのため、私は配布資料を探しているのではなく、正しい方向へのポイントを探しているだけです。他の提案は大歓迎です。
注: 「menu_test_input」関数が本当に必要ないことは承知していますが、今のところはそのままにしておきます。