Pay attention to format specifiers.
Code:
typedef struct
{
int day, month, year, pyear, pday, pmonth;
}date_t;
Code:
int getDate(date_t *d)
{
printf("Enter the day of when the car was made.\n");
if ( scanf("%s", &d->day) != 1 )
return -1;
printf("Enter the month of when the car was made .\n");
if ( scanf("%s", &d->month) != 1 )
return -1;
printf("Enter the year of when the car was made.\n");
if ( scanf("%d", &d->year) != 1 )
return -1;
printf("Enter the purchase day of when the car was made.\n");
if ( scanf("%s", &d->pday) != 1 )
return -1;
printf("Enter the purchase month of when the car was made .\n");
if ( scanf("%s", &d->pmonth) != 1 )
return -1;
printf("Enter the purchase year of when the car was made.\n");
if ( scanf("%d", &d->pyear) != 1 )
return -1;
return 0;
}
Code:
typedef struct
{
double capacity, currentLevel;
}tank_t;
Code:
void showTank(tank_t t)
{
printf("\n");
printf("The capacity of the tank is %lf\n", t.capacity);
printf("The current level is %s\n", t.currentLevel);
}
And pay attention to your own design.
Code:
int main(void)
{
car_t c;
date_t d;
tank_t t;
if ( getCar(&c) != 0 )
showCar(c);
if ( getDate(&d) != 0 )
showDate(d);
if ( getTank(&t) != 0 )
showTank(t);
return 0;
}
What value do the functions getCar, getDate, and getTank return on success? on failure?