I'm trying to write a program to test if a string is palindromic using only pointers
Code:
#include <stdio.h>
#include <string.h>
void revstr(char* str)
{
char* t,ch;
t = str;
while(*t != '\0')
{
t++;
}
t--;
while(str<t)
{
ch = *str;
*str = *t;
*t = ch;
str++;
t--;
}
}
int palin(char* str)
{
char* normal = (char*)malloc(sizeof(char)*strlen(str));
int i;
for(i=0;i<strlen(str);i++)
{
normal[i]=str[i];
}
revstr(str);
if(strcmp(normal,str) == 0)
return 1;
else
return 0;
}
int main()
{
char* str = (char*)malloc(sizeof(char)*100);
scanf("%s",&str);
printf("%d\n",palin(str));
return 0;
}
I need to change the arrays in the function int palin to pointers.