0
私は、配列内の特定の整数を検索するためのC++プログラムを作成していますが、プログラムをデバッグしようとすると、Visual Studio(vs 2015 proバージョンを使用しています)がデバッグアサーションの失敗:各引数はフォーマットの型指定子に対応型の変数へのポインタでなければなりませんデバッグアサーションが失敗しました!式:result_pointer!= nullptr
int main() {
int searchArray[10] = { 324,4567,6789,5421345,7,65,8965,12,342,485 };
//use searchKey for the number to be found
//use location for the array index of the found value
int searchKey, location;
//write code to determine if integers entered by
//the user are in searchArray
//initiate searchKey and location
searchKey = 0;
location = 0;
int n = sizeof(searchArray)/sizeof(searchArray[0]);
//let user define the search key, give -1 to quit
while (true)
{
std::cout << "Enter an integer ('-1') to quit: ";
scanf_s("%d", searchKey);
std::cout << searchKey << "\n";
if (searchKey == -1)
{
break;
}
for (location; location < n; location++)
{
if (searchArray[location] == searchKey)
{
break;
}
location = -1;
}
if (location != -1)
{
std::cout << searchKey << " is at location " << location << " in the array.\n";
}
else
{
std::cout << searchKey << " is not in the array.\n";
}
}
return 0;
}
この問題は解決しますか?あなたのコード行に "searchKey"の前に "&"を追加すると結果はどうですか? –