Please correct the mistake in my code

test cases are failing.

Hello @rajeev071999,

Please, share your code.
STEPS:

  1. Paste your code at https://ide.codingblocks.com/.
  2. Save it there.
  3. Share the URL generated.

You can also refer to my code:


It might help.

#include
#include
using namespace std;
char genchar(char s)
{
int i;
char c;
i=s-‘0’;
i–;
c=‘a’+i;
return c;
}
char genchar(char s1,char s2)
{
int i,j,num;
char c;
i=s1-‘0’;
j=s2-‘0’;
num=i*10+j;
num–;
c=‘a’+num;
return c;
}
void gencodes(char *inp,char *outp,int i,int j,int len)
{
if(i==len)
{
outp[j]=’\0’;
cout<<outp<<endl;
return;
}
outp[j]=genchar(inp[i]);
gencodes(inp,outp,i+1,j+1,len);
if(i<len-1)
{
int k;
k=inp[i+1]-‘0’;
if(inp[i]==‘1’)
{
outp[j]=genchar(inp[i],inp[i+1]);
}
else if(inp[i]==‘2’ && k<7)
{
outp[j]=genchar(inp[i],inp[i+1]);
}
gencodes(inp,outp,i+2,j+1,len);

}
return;

}
int main()
{
char inp[1000],outp[1000];
cin>>inp;
gencodes(inp,outp,0,0,strlen(inp));
return 0;
}

Hello @rajeev071999,

I have corrected your code:

Refer to the comments to understand your mistake.

Hope, this would help.
Give a like if you are satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.