ken@rochester.ARPA (SKY) (11/20/86)
Murphy strikes again. First fix is an off by one error. Second fix
allows the program to continue on other arguments after an invalid
code.
Thanks to all who told me about *grep. I use and like Unix, but I run
this program on a Z-80 machine.
Ken
*** /tmp/areacode.c Thu Nov 20 10:17:06 1986
--- areacode.c Thu Nov 20 10:23:34 1986
***************
*** 183,189
register int i, high, low, mid;
int strncmp();
! low = 0; high = sizeof(areacode) / sizeof(areacode[0]);
while (low <= high)
{
mid = (low + high) / 2;
--- 183,189 -----
register int i, high, low, mid;
int strncmp();
! low = 0; high = sizeof(areacode) / sizeof(areacode[0]) - 1;
while (low <= high)
{
mid = (low + high) / 2;
***************
*** 205,211
if (!isdigit(code[0]) || !isdigit(code[1]) || !isdigit(code[2])
|| code[3] != '\0')
- {
printf("Area code %s is not a valid area code!\n", code);
exit(1);
}
--- 205,210 -----
if (!isdigit(code[0]) || !isdigit(code[1]) || !isdigit(code[2])
|| code[3] != '\0')
printf("Area code %s is not a valid area code!\n", code);
else
printf("Area code %s is %s.\n", code, where(code));
***************
*** 207,215
|| code[3] != '\0')
{
printf("Area code %s is not a valid area code!\n", code);
! exit(1);
! }
! printf("Area code %s is %s.\n", code, where(code));
}
main(argc, argv)
--- 206,213 -----
if (!isdigit(code[0]) || !isdigit(code[1]) || !isdigit(code[2])
|| code[3] != '\0')
printf("Area code %s is not a valid area code!\n", code);
! else
! printf("Area code %s is %s.\n", code, where(code));
}
main(argc, argv)