having a problem of resetting thee char array sub_s by making the 0th index as ‘\0’, but i think it is not working,
code:
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(char sub_s[1000])
{
int i=0;
int j= strlen(sub_s)-1;
while(i <j)
{
if(sub_s[i] != sub_s[j])
{
return false;
}
i++;
j–;
}
return true;
}
int main()
{
char s[1000];
cin.getline(s,1000);
char sub_s[1000];
int cnt =0;
int i=0, j=0;
int k=strlen(s) -1;
while(i <=k)
{
while(j <=k)
{
int start =i;
int m=0;
while(start <= j)
{
sub_s[m] = s[start];
start++;
m++;
}
int length = strlen(sub_s);
sub_s[length] = ‘\0’;
if(isPalindrome(sub_s) == true)
{
cnt++;
}
j++;
}
i++;
j=i;
sub_s[0]= ‘\0’;
}
cout << cnt;
return 0;
}