//gettysburg.txt
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *tmp,*m,*t;
char *cpy,*max;
int size=0,m1=0;
//Functions Declaration
void lp();
void ispal();
//Program Starts Here
int main()
{
char c;
int i=0;
FILE *f;
f=fopen("gettysburg.txt","r+");
//Count the size of File & allocate size for a string
while(c!=EOF)
{
c=getc(f);
size++;
}
tmp= (char *) malloc(size*sizeof(char));
cpy= (char *) malloc(size*sizeof(char));
c=' ';
//Copy chars from a file into a String
rewind(f);
while(c!=EOF)
{
c=getc(f);
tmp[i]=c;
i++;
}
tmp[i]='\0';
lp();
return 0;
}
//Function For largest Palindrome
void lp()
{
int len ,i, k,n,r;
len= strlen(tmp);
t=(char *) malloc(size*sizeof(char));
max=(char *) malloc(size*sizeof(char));
for(i=0;i<(len);i++)
{
for(k=0;k<len;k++)
{
r=0;
for(n=i;n<((len-1)-k);n++)
{
t[r]=tmp[n];
r++;
}
t[n]='\0';
ispal();
}
}
//Here We go!!!!
printf("\n Largest palindrome %s ",max);
}
//Function to check Pal
void ispal()
{
int l;
l=strlen(t);
strcpy(cpy,t);
strrev(cpy);
if(strcmp(t,cpy)==0)
{
if(l>m1)
{
m1=l;
strcpy(max,t);
}
}
}