Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CharSearch
//g++ 7.4.0 //CharSearch // write a function that searches n bytes beginning with s for the character c, where n is the number of bytes that has to be incremented before it points to the null character; if the character is found a pointer to it is returned, otherwise return NULL; //this code is created by Rezaul Hoque on July 29, 2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int n=7; char* chr(char* ,char); char* chr(char* s,char c){ char * p= s;//pointer p is assigned to indicate the first element of array s while(*p!=NULL)//till pointer p indicates the NULL character,do the following things { if(*p==c)// if *p(value indicated by the pointer) is the desired character then return the address return p; ++p;//increment the pointer } return NULL; } int main() { char s[7]="ABCDEF"; char c; char * p; cin>>c; if(p=chr(s,c)) { cout<<c<<" is found at "<<p; } else { cout <<c<<" is not found"; } return 0; }
run
|
edit
|
history
|
help
0
no_error
Kth Smallest Element (with extra space)
MatrixVectorConversion
1234
remove_30-Seconds-of-C++
find-missing-number-arithmetic-progression
Algoritm(prelucrare cifre)
completed
list_of pair strings
დიოფანტეს განტოლება