- 3

String strchr() Function

https://code.sololearn.com/cA19A16A191A 8.8 Write the strchr() function. the code works fine in codeblocks. Idk why it is causing an error here. Anyway, my question is , in line 11 what is the use of p && *p?

28th Apr 2021, 8:01 PM
Ramisa Fariha
Ramisa Fariha - avatar
4 Answers
+ 4
It's giving you error because you have two functions of same name and parameters in your program. You are including cstring header file which contains strchr function already and then you are declaring your own function. Just rename your strchr function or just don't include cstring header file. You can't have two functions of same name in one program. https://code.sololearn.com/cmuO8BTYzkwD/?ref=app
28th Apr 2021, 8:36 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 2
If you are running a loop then you need to stop it at some point. Right! p && *p is used to check if pointer points to valid memory area. It is also checking Null Character '\0'. You are using it in for loops as condition. When your pointer p will be at Null Character then it will return 0 and your loop will break.
28th Apr 2021, 8:48 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
Ok @shail Thanks
28th Apr 2021, 8:40 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
hi
30th Apr 2021, 7:06 AM
Beautiful places of sri lanka.
Beautiful places of sri lanka. - avatar