ошибка C2664: show_info: невозможно преобразовать параметр 2 из ‘char [20]’ в ‘char

У меня небольшая структура:

struct price
{
char name[20];
char shop[20];
int pr;
price *next;
};

Функция, которая не работает:

void show_info(price *&head, char cur)
{
bool found = 0;
price *temp = new price;
temp->name = cur;
for (price *i=head; i!=NULL; i=i->next)
if (temp == i)
{
cout<< i->shop << i->pr;
found = 1;
}
if (!found)
cout << "The the good with such name is not found";
delete temp;
}

Основной файл:

int main()
{
price *price_list=NULL;
char inf[20];
list_fill(price_list);
cout << "Info about goods: ";
show_list(price_list); //there is no problem
cout <<"Input goods name you want to know about: ";
cin >> inf;
cout << "The info about good " << inf << show_info(price_list,inf)<<endl;
system("pause");
return 0;
}

Мне нужно исправить свою функцию, чтобы она могла работать правильно.

Как заявлено, ошибка c2664.

-4

Решение

Перепишите функцию следующим образом

#include <cstring>

//...

void show_info( const price *head, const char *cur )
{
bool found = false;
const price *i = head;

for ( ; i != NULL && !found; i = i->next )
{
found = strcmp( i->name, cur ) == 0;
}

if ( found )
{
cout<< i->shop << i->pr;
}
else
{
cout << "The the good with such name is not found";
}
}
0

Другие решения

void show_list(price *&head, char cur)

должно быть

void show_list(price *&head, char cur[] )

как вы проходите inf то есть char [20] в show_info(price_list,inf)

PS: есть может быть быть и другие проблемы

1

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector