I’ve figured out on how to work around the string but I can’t seem to get it to work.
Maybe it’s because of the scanf that I’m using.
Please advise 🙂
#include<stdio.h>
#include<string.h>
int do_palindrome(char *str, int offset){
int ok = 1;
int length = strlen(str);
if(length/2 > 0)
ok = (str[0] == str[length - 1 - offset])?
do_palindrome(++str, ++offset):0;
return ok;
}
int main(){
int i = 0;
int ok = 0;
char* str[1] ;
scanf("%c", str[1]);
ok = do_palindrome(str[0], 0);
printf("%s is palindrome? : %d\n", str[0], ok);
printf("Finished!");
return 0;
}
declares an array of one char pointer
reads a single char but tries to place it beyond the end of your array (C arrays are zero-based).
I think you want to read a string (char array). You can do this using