*** C newbie here. ***
My program has an array that holds an HTML document (one array cell per HTML character). I have a while-loop which loops over each cell of the array. At each array cell I check to see if the cell value is the start of a certain string; for example, does the current cell contain '&' and the next cell contain 'n' and the next 'b' and then 's' and then 'p' and then ';' (i.e., " "
).
I wrote a function to do the comparison. See below. Does C already have a function which does this comparison? If not, is the function that I show below how a C expert would write it? If no, how would a C expert write the function?
// p points to a cell in an array
// s is a string
// This function answers the question: does p start with s?
int cmpString(char *p, char *s) {
char *q = p; // Don't modify the position of the array pointer so make a copy
while (*s != 0) {
if (tolower(*q) != tolower(*s))
return 0;
q++;
s++;
}
return 1;
}