Advertisement
SVXX

C Version of ASM Code

Jan 6th, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int test(char* string)
  5. {
  6.     int len = strlen(string);
  7.     if(len > 1)
  8.     {
  9.         if(*string == *(string + len - 1)) //If first char equals the last.
  10.         {
  11.             *(string + len - 1) = 0;
  12.             string++;
  13.             return test(string);   
  14.         }
  15.         else
  16.             return 0;
  17.     }
  18.     else
  19.         return 1; //One letter strings are palindromes anyway
  20. }
  21.  
  22. void main()
  23. {
  24.     char teststr[] = "ababa"; //Try other cases.
  25.     if(test(teststr) == 1)
  26.         printf("Palindrome success\n");
  27.     else
  28.         printf("Fail\n");
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement