Software Designer Examination

1. Write a function which tests if a string matches with a pattern string in
C language. It must follow the declarations below and have a document about
algorithm. Pattern contains following meta-characters:
* Matches zero or any characters
? Matches any character

Declaration
int wildmatch(strPat, strSrc)

Parameters
A pattern string and a test source string.

Return value
A boolean value. true or false.


Test Cases:
testIt(1, "*sh*", "shshsh");
testIt(0, "*shp", "shshsh");
testIt(1, "*shp*", "shshpsh");
testIt(1, "*sh", "shshsh");

testIt(1, "f*.cpp", "foo.cpp");
testIt(1, "foo.cpp", "foo.cpp");
testIt(1, "foo*", "foo.cpp");
testIt(1, "fo*.cpp", "foo.cpp");
testIt(1, "*.cpp", "foo.cpp");
testIt(1, "*", "foo.cpp");
testIt(1, "f*", "foo.cpp");
testIt(1, "fo*", "foo.cpp");

testIt(1, "f??.???", "foo.cpp");
testIt(0, "f??.??", "foo.cpp");
testIt(1, "f??.*", "foo.cpp");
testIt(1, "f??.*p", "foo.cpp");
testIt(0, "", "foo.cpp");

testIt(0, "fo*.h", "foo.cpp");

2. Write function to detect loop in single-linked list using constant memory
space. You can not modify specified list.


struct CCons
{
int m_iData;
CCons* m_pNext;
}; // struct CCons

int hasLoop(const CCons* pList)
{

}


3. Create command called “tail” which accepts file names as command line
arguments and display the last part of files. Synopsis of “tail” command
is


Usage: tail [-n number] [file…]


If ?n option is specified, tail displays the last n lines of files,
otherwise displays the last 10 lines. If no file is specified in command
line, tail reads standard input.

Implementation should be simple and efficient with strict error checking.