i am also seeing the similar problem.. the code is here..
#include<stdio.h>
#include<string.h>
int palindrome(char *a,int n);
int main()
{
char a[20];
int b,n;
printf("Enter the string to be checked\n");
scanf("%s",a);
printf("The entered string is ");
puts(a);
printf("%c%c%c",a[0],a[1],a[2]);
//empty line
strlen(a);
b=palindrome(a,n);
if(b==0)
printf("%s is palindrome\n",a);
else
printf("%s is not palindrome\n",a);
}
int palindrome(char *a,int n)
{
int i=0;
int j=n-1;
for(;i<j;i++,j--)
{
//no empty line
//printf("%d",i);
printf("%c",a[i]);
printf("%c",a[j]);
//printf("%d",strcmp(a[i],a[j]));
if(a[i]!=a[j])
return(0);
}
return(1);
}
i wrote similar code in other format...
#include<stdio.h>
#include<string.h>
int palindrome(char *a, int n);
int main()
{
char a[20];
//char b[20];
int c,n;
printf("Enter the string to check");
scanf("%s",a);
//scanf("%s",b);
//printf("The entered string is ");
puts(a);
//puts(b);
n=strlen(a);
c=palindrome(a,n);
if(c==0)
printf("The string is palindrome");
else
printf("The string is not palindrome");
}
int palindrome(char *a, int n)
{
int i=0,j=n-1;
for(;i<j;i++,j--)
//{
//printf("%c ",a[i]);
//printf("%c",a[j]);
if(a[i]!=a[j])
return(1);
//}
return(0);
}
The second one is working.. the first one returns error of segmentation fault core dump.
I am using cygwin gcc recent version for compilation. The error file is generated for first code upon executing with extn of .stackdump.
The error file is
Exception: STATUS_ACCESS_VIOLATION at eip=00401144
eax=49662080 ebx=61227A1E ecx=6115B320 edx=00000000 esi=61227A2D edi=00000000
ebp=0022CCF8 esp=0022CCE0 program=C:\cygwin\home\LP-0126\palindrome.exe, pid 3536, thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
0022CCF8 00401144 (0022CD40, 49435341, 00000065, 0000006E)
0022CD68 004010D6 (00000001, 61227AA4, 006700F8, 610049BE)
0022CD98 61006E73 (00000000, 0022CDD4, 61006720, 7FFD5000)
End of stack trace