Answer the question
In order to leave comments, you need to log in
What is the sort error?
Please help me find the error.
It is required to display the titles of books of a certain author (apparently, you need to enter the author's surname from the keyboard), published after 2000.
When I enter any last name, "No" is displayed
void year (list begin)
{
char surname [15];
int year, k = -1;
list pos;
system ("CLS");
if (!begin) // если список пуст
{
puts ("List is empty");
system("pause");
return;
}
getchar();
puts ("Surname?");
scanf ("%c", &surname);
while (begin) //пока в списке есть эл-ты
{
k++;
if (begin->data.surname == surname && begin->data.year > 2000)
{
year = begin->data.year;
pos = begin;
}
begin = begin->next; // переставляем указатель на след эл-т
// free (temp); // удаляем первый
}
if (year <= 0 || year >= 2020) puts ("No");
else printf ("Title : %s\n", pos->data.title);
system("pause");
}
Answer the question
In order to leave comments, you need to log in
apparently you need to enter the author's last name from the keyboard
if (begin->data.surname == surname && begin->data.year > 2000) // false false false false ...
{
year = begin->data.year;
pos = begin;
}
int year
??? while(begin) //пока в списке есть эл-ты
{
if(begin->data.year > 2000 && !strcmp(begin->data.surname, surname))
{
printf("Title : %s\n", begin->data.title);
}
begin = begin->next;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question