this section gives an example for pointers: look for the existence of a character in a data structure.
the following is what I wrote routinely:
-sharpinclude <stdio.h>
-sharpdefine TRUE 1
-sharpdefine FALSE 0
int find_str(char **, char);
int find_str_1(char **, char);
int main()
{
char *strings[] = {
"there is a dog.",
"no,that"s a cat.",
NULL
};
int ret;
ret = find_str(strings, "m"); //strings
//ret = find_str_1(strings, "m"); //strings
printf("%d\n", ret);
return 0;
}
int find_str(char **strings, char value)
{
while (*strings != NULL) {
while (**strings != "\0") { //1
if (*(*strings)PP == value) {
return TRUE;
}
}
stringsPP; //"there is a dog."1strings:stringsfind_str_1()
}
return FALSE;
}
int find_str_1(char **strings, char value)
{
char *line;
while ((line = *strings) != NULL) {
while(*line != "\0"){
if (*linePP == value) {
return TRUE;
}
}
stringsPP;
}
return FALSE;
}
what puzzles me is that
find_str () changes the passed-in parameters, while find_str_1 (does not change the passed-in parameters.
and when I GDB debug find_str (), breakpoint 1 is set to detect "there is a dog." The strings value (which is an address) remains the same during the process of whether the target character"m"is included in the string. So in find_str (), which sentence causes the incoming pointer strings to be modified?