What's wrong in my approach?
in else condition you also have to update p array
see in modified Code at line no 16
p[j]=s[0];
to print p array in main()
just use cout<<p<<endl;
you can see all changes in modified code below
Modified Code
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like : and don’t forgot to mark doubt as resolved