I am having a hard time with this excercise. Can anyone give me a suggestion?
thanks
Printable View
I am having a hard time with this excercise. Can anyone give me a suggestion?
thanks
I know how to do it now :)
chucked this together, not everything is declared but should give you an idea how to do it..
Code:int i = 0;
int numAppearances = 0;
while (string[i] != '\0') {
int j = 0;
while (j < substringLength) {
if (string[i++] == substring[j++]) {
if (j == substringLength) {
numAppearances++;
}
}
else {
break;
}
}
}
Or just strstr()... or strcmp(). Why are people scared of pointers!?
Why bother with some thing that the standard library supplies?
Practice is derived from practical,
It's practical to use the standard C functions. Hence, you practice practicallity.
It's less code, and teaches you more IMO. If it's an assignment, which it appears to be -- unless otherwise stated it'd be a waste of time to reinvent the wheel.