Home > Back-end >  Pointer to a pointer in c
Pointer to a pointer in c

Time:01-07

#include
#include
#include

//the application of pointer to a pointer
Int main ()
{
//design a function: void find1 (char array [], char search, char * pa)
//request: this function parameter arrays in array is with zero value for the end of the string, in string
//in the array to find character is the characters in the search parameters, if found, the function through the third parameter (pa)
//the return value is an array of the first to find the character of a string address, if not found, for the pa to 0,

Void find1 (char array [], char search, char * * q);

Char array []="abcdefghijklmnopqrstuvwxy";
Char search;
Char * p;
Char c='! ';
Char * PC;

PC=& amp; c;

Printf (" please enter the characters you want to find the order: ");
The scanf (" % c ", & amp; Search);

Find1 (array, search, & amp; P);

Printf (" % c ", * p).

return 0;
}

Void find1 (char array [], char search, char * * q)//* * p is a pointer to a pointer, hold is the address of a pointer, * q is a pointer, the pointer is the display function of p
{
int i;

For (I=0; * (array + I)!=0; I++)
{
If (search==* (array + I))
{
* q=array + I;
break;
}

Else if (* (array + I)==0)
{
* q=0; //a little small problem, is looking for is not the time for the elements in the array, the black window will not output
}
}
}
this is a piece of code I consult a electronic writing, and then there are some problems: the above red comments
Output is as follows:
Now I hope to look for is not in the array of characters in my character, I can output a! Such as

CodePudding user response:

The
Printf (" % c ", * p).
Change
Printf (" % c ", (* p==0? C: * p));
Because * p=0 is not a can display characters, so when the * p==0 is printing c variable, because the value of the variable c is'! '
  • Related