Rescursive subsequence

im not understanding why am i getting wrong answer for every test case…please help

here is my code–

#include<bits/stdc++.h>

using namespace std;

int c=0;
string s;

void func(string s,vector x,int i){
if(s[i]==’\0’){
x.push_back(’\0’);
for(unsigned int i=0;i<x.size();i++)
cout<<x[i];
cout<<" ";
c++;
return ;
}
func(s,x,i+1);
x.push_back(s[i]);
func(s,x,i+1);

}

int main(){

//string s,x='';

cin>>s;
vector<char> x;
func(s,x,0);
cout<<endl<<c<<endl;

return 0;

}

please save your code on the online ide of coding blocks

here–

there are errors in your code
like you are declaring strings but terminating it with a ‘\0’ secondly you are declaring vector of type char but you have to actually deal with the strings.
try thinking about the some other approach. try doing this with recursion.
if you still have doubt then let me know.

so whats the problem??strings do terminate with null character…
and i’ve used char type vector because we have to iterate over characters of the only string provided??
otherwise how will we recurse??

I am suggesting to use this one
void printsubseq(string q, string ans) {

if (q.length() == 0) {
	cout<<ans<<" ";
	return;
}

char ch = q[0];
string ros = q.substr(1);

printsubseq(ros, ans);

printsubseq(ros, ans + ch);

}

and for count make similar function with return type int
count both the call
and base case when q.length()==0
return 1

ma’am…i got the correct answer with my previous code only…when i commented line number 10…can u please tell me what was the problem with pushing null character in the vector…
why was it giving wrong answer??

actually you mentioned that you got wrong answers with all cases that’s why i suggested you this method.

@Prajawal-Pandey-2140320206067139 there is some problem in your code it is not running and not submitting.

I would suggest you to push ’ '(space) instead of pushing ‘\0’ and in your output you are putting extra space.