Hello guys

Could anone please check my programme,
this program is for checking if a string is a palindrome or not
(written in dev c++)
PROGRAMME
_______________________________
#include<iostream>
#include<string>
int main()
{
char arr[8];
int size=strlen(arr);
cin>>arr;
for(int i=0;arr[i]!='\0';i++){
if(arr[i]==arr[size-1-i])
cout<<"It is a paldrome";
else
cout<<"It is not a palindrome";
getchar();
return 0;
}
int size=strlen(arr);

That won't work because strlen starts counting at the beginning of the array, and counts until it reaches the number 0. You've not set any of the values in the array. All, some or none of them might be zero.
It may also be worth noting that you're using an char[] for the inputted string, while you already use the string library. Using an std::string might be of more value.
always initialize!

specifically you should change
1
2
int size=strlen(arr);
cin>>arr;


to
1
2
3
int size=0;
cin>>arr;
size=strlen(arr);
thanks
Topic archived. No new replies allowed.