Smart keypad-one test case is failing

#include<bits/stdc++.h>
using namespace std;

char table[][10] = { " ", “.+@$”, “abc”, “def”, “ghi”, “jkl” , “mno”, “pqrs” , “tuv”, “wxyz” };

void keypad(char *in,char *out,int i,int j)
{
if(in[i]==’\0’)
{
out[j]==’\0’;
cout<<out<<endl;
return;

 }

int dig=in[i]-'0';

for(int k=0;table[dig][k]!='\0';k++)
{    out[j]=table[dig][k];
    keypad(in,out,i+1,j+1);
}

}

int main() {
char in[100],out[100];
cin>>in;

keypad(in,out,0,0);

return 0;

}

Hey @ankityadav943, you haven’t wrote the case when table[digit]==" ".

Add these lines after base case
if(table[digit] =="")
keypad(in,out,i+1,j);

still not working…#include<bits/stdc++.h> using namespace std; char table[][10] = { " “, “.+@$”, “abc”, “def”, “ghi”, “jkl” , “mno”, “pqrs” , “tuv”, “wxyz” }; void keypad(char *in,char *out,int i,int j) { int dig; if(in[i]==’\0’) { out[j]==’\0’; cout<<out<<endl; return; } if(table[dig]==” ") keypad(in,out,i+1,j); dig=in[i]-‘0’; for(int k=0;table[dig][k]!=’\0’;k++) { out[j]=table[dig][k]; keypad(in,out,i+1,j+1); } } int main() { char in[100],out[100]; cin>>in; keypad(in,out,0,0); return 0; }

hey @ankityadav943, please share the code saved in coding blocks ide as text gets mismatch here.

hey @ankityadav943, use have written out[j]==’\0’ instead of out[j]=’\0’. Moreover digit variable should assigned the value before checking for empty string.
I have made changes to your code,you can check them here https://ide.codingblocks.com/s/106550

1 Like

hey @ankityadav943 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved