Can anyone help me to answer the following questions? Thanks a lot!
1) Given the following code snippet, what does the function DoesWhat()
do? And what, if any, assumptions are made about the input to the
function.
struct _tagElement
{
int m_cRef;
unsigned char m_bData[20];
struct _tagElement * m_next;
} NODE, * PNODE;
PNODE DoesWhat (PNODE pn1, PNODE pn2)
{
PNODE * ppnV = &pn1;
PNODE * ppn1 = &pn1;
PNODE * ppn2 = &pn2;
for ( ; *ppn1 || *ppn2; ppn1 = &((*ppn1)->m_next))
{
if (!(*ppn1) || (0 < memcmp((*ppn1)->m_bData,
(*ppn2)->m_bData, sizeof((*ppn2)->m_bData))))
{
PNODE pn = *ppn1;
*ppn1 = *ppn2;
pn2 = (*ppn2)->m_next;
(*ppn1)->m_next = pn;
}
}
return *ppnV;
}
2) What are the problems with the quality of the previous code and how
would you make it better? Please try to find as many problems as you
can.
3) Write the code for the function below. Parameters data and filter
are null-terminated strings. Scan removes all occurrences of the
string filter from the string data.
int scan(char *data, char *filter);