Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define ALPHANUM "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
  6.  
  7. void fnPurge (char* input, char* output);
  8. char* fnTest (char* output); //This is going to return "is" or "is not"
  9.  
  10. int main (void)
  11. {
  12.  //local declarations
  13.   char chInput[100];
  14.   char chClean[100];
  15.  
  16.   //get input
  17.   printf("This will test a string of up to 100 characters for palindromicity. \n\nEnter string ==> ");
  18.   fgets(chInput, 100, stdin);
  19.   //scanf("%100[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890]",chClean);
  20.   //purge it
  21.   fnPurge (chInput, chClean);
  22.   //printf ("%s\n",chClean); //diagnostics
  23.   //printf ("%s\n%s\n", chClean,chRev); //just kidding
  24.  
  25.   //test for palindromicity
  26.   printf ("The string %s a palindrome. \n",fnTest (chClean));
  27.  
  28.   return 0;
  29. }
  30.  
  31. void fnPurge (char* input, char* output)
  32. {
  33.  
  34.   int size;
  35.   int outincr;
  36.   int i;
  37.   outincr = 0;
  38.   size = 0;
  39.  
  40.   size = strlen(input);
  41.  
  42.  
  43.  
  44.    while (*input != '\0')
  45.   {
  46.     size = strspn(input,ALPHANUM);
  47.     input[size] = '\0';
  48.     strncat (output, input, 99 - strlen(output));
  49.     input += size + 1;
  50.   }
  51.  
  52.  
  53.   return;
  54. }
  55.  
  56. char* fnTest (char* output)
  57. {
  58.   char reverse[100];
  59.   int length;
  60.   char temp;
  61.   int i;
  62.   length = strlen(output);
  63.  
  64.   for (i = 0; i < length; i++)
  65.   {
  66.     output[length - i -1] = toupper(output[length - i -1]);
  67.    
  68.     reverse[i] = output[length - i - 1];
  69.    
  70.      
  71.   }
  72.   reverse[length] = '\0';
  73.  
  74.   printf("%s %s\n",output, reverse);
  75.  
  76.   if (0 == strcmp (reverse, output)) //return text for the user
  77.     return "is";
  78.   else
  79.     return "is not";
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement