Re: c++ Structures export data for specific name, country, last name
Well I do it like this:
Code:
char choose[1];
do {
cout << "New check? Y/N \n";
cin >> choose;
if (_stricmp("N", choose) == 0)
{
break;
}
char name_for_check[10];
cout << "\n Name for check:";
cin >> name_for_check;
for (i = 0; i < n; i++)
{
if (strcmp(array[i].first_name, name_for_check) == 0)
{
cout << array[i].first_name << " ";
cout << array[i].last_name << " ";
cout << array[i].country << endl;
}
}
}
while (_stricmp("Y", choose) == 0);
system("pause");
}
The code is working but after I run it it show this message:
Quote:
Run-Time Check Failure #2 - Stack around the variable 'choose' was corrupted.
Re: c++ Structures export data for specific name, country, last name
As choose is defined to be a c-style string and not a char, then
is going to treat choose as a c-style array and terminate it with a null. This makes the string at least 2 chars but you have only allocated space for 1!
This is why using c-style strings in a c++ program is a bad idea Get your teacher to explain using the c++ string type.