c - call strings by pointers in functions (syntax) -
i trying write function checks if string palindrome, think have mistakes in using pointers strings. wrong code?
#include<stdio.h> #include<string.h> #define max 1000 int ispalindrome(char *); void main(){ int i; char *string[max], *string2[max]; gets(string); for(; *string!=null; ++string){ toupper(string); if(isspace(string)==1 || isalnum(string)==0 ) for(string2=string; *(string2 +1)!=null ;++string2) *string2=*(string2 +1); if(ispalindrome(*string)==1) printf("yes"); else printf("no"); return 0; } int ispalindrome(char *string){ size_t p; static int i; p=strlen(string) -1; if( *string!= *(string+p-i)) return 0; if(string>=string +p -i) return 1; else{ ++i; return ispalindrome( *(string+1)) ; } }
your code written if sting type char * should turn
char *string[max], *string2[max];
into
char buffer[max] ; char *string = buffer ; char buffer2[max]; char *string2 = buffer2 ;
Comments
Post a Comment