Bugs
You don't reset findCounter
properly, resulting in this miscount:
enter text: asdasd
found!!! 1
times
Your function tests for findCounter == 3
, but accepts a find
parameter of any length.
Style
Never omit the "optional" braces for your if
statements, especially if the statement spans more than one line. You will eventually contribute to a coding accident, and it will be your fault.
Your loop is awkward, especially the -1
in ... while (str[strCounter-1] != '0円')
. A for
loop would be more idiomatic and readable:
for (int strCounter = 0; str[strCounter] != '0円'; strCounter++) {
...if (str[strCounter] == find[findCounter]) {
findCounter++;
if (findCounter == findLen) {
findCounter = 0;
howMany++;
}
} else {
findCounter = 0;
}
}
Avoid using unsigned
integers; they cause more trouble than they are worth.
Bugs
You don't reset findCounter
properly, resulting in this miscount:
enter text: asdasd
found!!! 1
times
Your function tests for findCounter == 3
, but accepts a find
parameter of any length.
Style
Never omit the "optional" braces for your if
statements, especially if the statement spans more than one line. You will eventually contribute to a coding accident, and it will be your fault.
Your loop is awkward, especially the -1
in ... while (str[strCounter-1] != '0円')
. A for
loop would be more idiomatic and readable:
for (int strCounter = 0; str[strCounter] != '0円'; strCounter++) {
...
}
Avoid using unsigned
integers; they cause more trouble than they are worth.
Bugs
You don't reset findCounter
properly, resulting in this miscount:
enter text: asdasd
found!!! 1
times
Your function tests for findCounter == 3
, but accepts a find
parameter of any length.
Style
Never omit the "optional" braces for your if
statements, especially if the statement spans more than one line. You will eventually contribute to a coding accident, and it will be your fault.
Your loop is awkward, especially the -1
in ... while (str[strCounter-1] != '0円')
. A for
loop would be more idiomatic and readable:
for (int strCounter = 0; str[strCounter] != '0円'; strCounter++) {
if (str[strCounter] == find[findCounter]) {
findCounter++;
if (findCounter == findLen) {
findCounter = 0;
howMany++;
}
} else {
findCounter = 0;
}
}
Avoid using unsigned
integers; they cause more trouble than they are worth.
Bugs
You don't reset findCounter
properly, resulting in this miscount:
enter text: asdasd
found!!! 1
times
Your function tests for findCounter == 3
, but accepts a find
parameter of any length.
Style
Never omit the "optional" braces for your if
statements, especially if the statement spans more than one line. You will eventually contribute to a coding accident, and it will be your fault.
Your loop is awkward, especially the -1
in ... while (str[strCounter-1] != '0円')
. A for
loop would be more idiomatic and readable:
for (int strCounter = 0; str[strCounter] != '0円'; strCounter++) {
...
}
Avoid using unsigned
integers; they cause more trouble than they are worth.