I have made this program which generally works fine unless I enter a string with a length of over 50 or a 0 string. What is going on with my else if statements? I can't find the problem although I checked it many times. Here's the code:
#include<stdio.h>
main()
{
char string1[1000] ,i, k,j, sum;
int length;
printf("Dwse leksh\n");
scanf("%s", string1);
sum=0;
for(i=0; string1[i]!= '\0'; ++i)
{
length=i+1;
}
printf("Length of string is %d\n", length);
if(length>0 && length<=50)
{
k=length-1;
for(j=0; j<k; j++)
{
if(string1[j]==string1[k])
sum=sum+1;
k--;
}
if(sum==length/2 || sum==length-1)
{
printf("The word is palindrome\n");
}
else
{
printf("The word is not palindrome\n");
}
}
else if(length=0)
{
printf("Error: mideniki sumboloseira");
}
else if(length>50)
{
printf("Error: uperbash tou oriou 50 xaraktirwn");
}
}
Aucun commentaire:
Enregistrer un commentaire