Suppose, for example, that some k which is an arbitrary number=2 k=2, then there is code in C:
int wordcomp(char *p, char *q) {
int n = k;
for ( ; *p == *q ; p++, q++) {
if ( *p==0 && --n == 0 )
return 0;
}
return *p - *q;
}
Please explain to me what this code does? Also, what does *p-*q mean? Also, how is it implemented in Java?
It compares two words
It means, Tell me the value of char the pointer p is pointing to, and rest it to the char the pointer q is pointing to.
The
*p-*qpart? Here is it.If you mean the whole function, this could help you to get started:
You need to validate limits tough.