2008. 4. 29. 10:40ㆍETC Programmings
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int getLength(char *str){
int count = 0;
for(;;){
if (*str == '\0')
break;
else {
count++;
str++;
}
}
return count;
}
int compareStr(char *str1, char *str2){
int i;
int isSame = 0;
for(i = 0 ; i < getLength(str1) ; i++){
//printf("%c 와%c 의비교", str1[i], str2[i]);
if (str1[i] == str2[i])
isSame = 1;
else
isSame = 0;
}
return isSame;
}
int compareReverse(char *str){
int i = getLength(str) - 1;
int j;
char *reverse;
reverse = (char*) calloc(getLength(str),sizeof(char));
for(j = 0 ; i >=0 ; i--, j++)
reverse[j] = str[i];
return compareStr(str, reverse);
}
int main(void){
char *str = "123213";
compareReverse(str);
printf("Input string %s\n",str);
if(compareReverse(str))
printf("TRUE");
else
printf("FALSE");
}
음하하... recursion 시간인데 이러고 있다... recursion으로 바꿔보세~