Article View: net.sources.bugs
Article #867Re: areacode.c
From: SKY
Date: Thu, 20 Nov 1986 15:30
Date: Thu, 20 Nov 1986 15:30
67 lines
2207 bytes
2207 bytes
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)
Technical Details
Message-ID:
<22587@rochester.ARPA>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!kenShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rochester!ken From: ken@rochester.ARPA (SKY) Newsgroups: net.sources.bugs Subject: Re: areacode.c Message-ID: <22587@rochester.ARPA> Date: Thu, 20-Nov-86 10:30:57 EST Article-I.D.: rocheste.22587 Posted: Thu Nov 20 10:30:57 1986 Date-Received: Thu, 20-Nov-86 22:52:58 EST Reply-To: ken@rochester.UUCP (SKY) Distribution: net Organization: U of Rochester, CS Dept, Rochester, NY Lines: 67