Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int is_palindrom(char niz[]);
int main(int argc, char *argv[])
{
if(argc<2)
{
printf("Need an argument-a word!\n");
exit(1);
}
if(strlen(argv[1])==0 || strlen(argv[1])==1)
{ printf("You have to input a word ,not a character!\n");
exit(1);
}
if(is_palindrom(argv[1])==0)
{
printf("A word %s is palindrom!\n",argv[1]);
}
else printf("A word %s is not a palindrom!\n",argv[1]);
}
int is_palindrom(char niz[])
{
char reverse_niz[strlen(niz)];
int i;
int x=0;
for(i=strlen(niz)-1;i>=0;i--)
{
reverse_niz[x]=niz[i];
x++;
}
reverse_niz[x]='\0';
if(strcmp(reverse_niz,niz)==0)
return 0;
else
return 1;
}
The above program works. A palindrom is a a word which can be read backwards the same as forward(ex. cepec). In the above program i first reversed the inputed word and stored it into reverse_niz and then compare that string to the original. And if the words are the same the thing is palindrom.
BUT I have to implement that function is_palindrom(char niz) using recursion. Somehow I have to make for the method to be callig itself in the body of a method.