I am new to programming in C and am trying to write a simple function that will compare strings. I am coming from java so I apologize if I'm making mistakes that seem simple. I have the following code:
/* check if a query string ps (of length k) appears
in ts (of length n) as a substring
If so, return 1. Else return 0
*/
int
simple_substr_match(const unsigned char *ps, /* the query string */
int k, /* the length of the query string */
const unsigned char *ts, /* the document string (Y) */
int n /* the length of the document Y */)
{
int i;
for(i = 0;i < n;i+k){
char comp;
comp = ts->substring(i,k);
if (strncmp(comp, ps, k)) {
return 1;
}
}
return 0;
}
When trying to compile i get the error: request for member 'substring' in something not a structure or union.
The idea of the code is describe in the code comment but just to elaborate I am looking to see if ps occurs as a substring of ts in increments of k(length of ps).
What am I doing wrong and how can I fix it? Is there a better way of doing what I am trying to do?
substringmethod.