Связный список, объясните ошибки - C (СИ)
Формулировка задачи:
#include <stdio.h>
#include <stdlib.h>
#include < string.h >
#include <assert.h>
typedef struct FIRM
{
char FIO[30];//ФИО сотрудника
char DATE[10];
char TIME_ARRIVAL[5];//время прихода
char TIME_CARE[5];//время ухода
struct Firm * next;
} Firm_t, * list_t;
int check_dates(char mass[10])//проверка ввода даты
{
int day, month, year;
if(mass[2]!='.' || mass[5]!='.') // Проверяем корректность формата
{
puts(" The date is incorrect");
return 0;
}
// Преобразуем строковые символы в числа
day = atoi(mass);
month = atoi(mass+3);
year = atoi(mass+6);
if((month==4 || month==6 || month==9 || month==11) && day>30) // если слишком много дней в коротком месяце
{
puts(" The day or month is incorrect");
return 0;
}
if(month==2 && day>28) // отдельно проверяем месяц февраль
{
puts(" The day or month is incorrect");
return 0;
}
if(day>31) // если введен слишком большой день
{
puts(" The day is incorrect");
return 0;
}
if(month>12) // если введен слишком большой месяц
{
puts(" The month is incorrect");
return 0;
}
return 1;
};
int check_time(char mass[5])//проверка ввода времени
{
int minute, hour;
if(mass[2]!=':') // Проверяем корректность формата
{
puts(" The time is incorrect");
return 0;
}
// Преобразуем строковые символы в числа
hour = atoi(mass);
minute = atoi(mass+3);
if(minute>60) // если введен слишком большой день
{
puts(" The minute is incorrect");
return 0;
}
if(hour>24) // если введен слишком большой месяц
{
puts(" The hour is incorrect");
return 0;
}
return 1;
};
Firm_t * Firm_new(const char FIOn[30],const char DATEn[10],const char TIME_ARRIVALn[5],const char TIME_CAREn[5])
{
Firm_t * pFirm = malloc(sizeof(Firm_t));
assert( pFirm );
strcpy (pFirm->FIO, FIOn);
strcpy (pFirm->DATE, DATEn);
strcpy (pFirm->TIME_ARRIVAL, TIME_ARRIVALn);
strcpy (pFirm->TIME_CARE, TIME_CAREn);
pFirm->next = NULL;
return pFirm;
}
int list_add(list_t * pList, Firm_t * pFirm)
{
return ( *pList && list_add(&((*pList)->next), pFirm) || ( *pList = pFirm ) );//main.c(98): error #2140: Type error in
argument 1 to 'list_add'; expected 'list_t *' but found '(incomplete) struct Firm * *'.
}
void list_purge(list_t list)
{
if ( list )
{
list_purge(list->next);//main.c(105): error #2140: Type error in argument 1 to 'list_purge'; expected 'list_t'
but found '(incomplete) struct Firm *'.
free(list);
}
}
void list_dump(list_t list)
{
if ( list )
{
printf("FIO: %s ", list->FIO);
printf("DATE: %s ", list->DATE);
printf("TIME ARRIVAL: %s ", list->TIME_ARRIVAL);
printf("TIME CARE: %s ", list->TIME_CARE);
list_dump(list->next);//main.c(118): error #2140: Type error in argument 1 to 'list_dump'; expected 'list_t'
but found '(incomplete) struct Firm *'.
}
}
int main(void)
{
char FIOc[30], DATEc[10], TIME_ARRIVALc[5], TIME_CAREc[5];
list_t list = NULL;
while(1)
{
printf("FIO: ");
fgets(FIOc,30,stdin);
if(strlen(FIOc)==1)
break;
while(1)
{
printf("date: ");
scanf("%s", DATEc);
if (check_dates(DATEc)==1)
break;
}
while(1)
{
printf("time_arrival: ");
scanf("%s", TIME_ARRIVALc);
if (check_time(TIME_ARRIVALc)==1)
break;
}
while(1)
{
printf("time_care: ");
scanf("%s", TIME_CAREc);
if (check_time(TIME_CAREc)==1)
break;
}
list_add(&list, Firm_new(FIOc, DATEc, TIME_ARRIVALc, TIME_CAREc));
}
list_dump(list);
list_purge(list);
return 0;
}Решение задачи: «Связный список, объясните ошибки»
textual
Листинг программы
list_purge((Firm_t *)list->next);