Author: Stan Eisenstat
Subject: Re: [Cs223] testDeque on nonexistent Deque 3
Date: Sunday, 05 Apr 2020, 12:45:38
> Message Posted By: Unknown
...
> I am still trying to fix my Deque implementation such that it will not
> crash when "Ia" is called after running testDeque. I have placed print
> statements to inform me when certain functions are called. I am seeing,
> however, that isEmptyD being called twice. The first time it is called,
> the passed in argument is null. The second time it is called, it prints
> out that the address of d is "0x1." I am not sure why Ia is calling
> isEmpty D twice and I cannot understand the reason behind the segmentation
> fault.
When Hwk4/testDeque.c sees an I command, it executes
the following code:
if (!isalpha(deque = getchar()))
printf ("%c is not alphabetic\n", deque);
else if (D[deque] == X && !isEmptyD (NULL))
printf ("isEmptyD(%c) detected invalid *D\n", deque);
else if (isEmptyD (&D[deque]))
printf ("Deque %c is empty\n", deque);
else
printf ("Deque %c is not empty\n", deque);
which carry out the following steps;
* If the next character (which specifies the name of
the Deque) is not an alphabetic, it prints a warning
message.
* otherwise if no Deque with that name has been created
and isEmptyD() correctly returns FALSE, it prints a
message that isEmptyD() detected an invalid Deque.
* Otherwise if isEmptyD() returns TRUE, it prints a
message that the Deque is empty.
* Otherwise it prints a message that the Deque is not
empty.
Since your isEmptyD() does not detect an invalid Deque,
it is called twice.
--Stan-
PREV
INDEX
NEXT