Conversion from string to int

//string to int
#include
#include

using namespace std;
int stringtoint(char c[],int n)
{
if(n==0)
return 0 ;
int digit=c[n-1]-β€˜0’;
int ans=stringtoint(c,n-1);

return ans*10+digit;

}
int main()
{
char a[]=β€œ1234”;
int len=strlen(a);
cout<<stringtoint(a,len)<<endl;
}

It is only passing test case 1 and not other test cases.

Hey @shubhangis248 i would request you to please share your code , using ide.codingblocks.com

It becomes difficult to share debugged codes :grinning:

Hey @shubhangis248 try to make your int main() function like this cause your stringtoint() function is working perfectly fine.
image
If it doesn’t works or doesn’t pass any test cases. Do let me know.
Happy to help :grinning: