![]() |
![]() |
![]() |
![]() |
![]() |
|
The check_owner function, defined next, exhibits a
railroad_car parameter, a character-pointer parameter, and an
integer return value, which is either 0 or 1 depending on
whether the car belongs to the railroad specified by the character-pointer
parameter. Note that the check_owner function uses strncmp,
a function supplied by the string-handling library, which tests two strings
to see whether a specified number of initial characters in the two strings
are the same:
// DANGEROUS; contributes to difficult-to-find bug:
int check_owner (railroad_car r, char *s) {
if (strncmp (s, r.serial_number, 3))
return 0;
else
return 1;
}