Interview Questions

Implement the function ....

Microsoft Interview Questions and Answers


(Continued from previous question...)

89. Implement the function ....

Question:
Implement the function
char* strstr(char* p, char*q)
which returns the pointer to the first occurence of the string q within string p. (Return NULL if either p or q is NULL or if q does not exist in p).


maybe an answer:


/* The class name doesn't have to be Main, as long as the class is not public. */

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}

(Continued on next question...)

Other Interview Questions