Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define ALPHANUM "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
- void fnPurge (char* input, char* output);
- char* fnTest (char* output); //This is going to return "is" or "is not"
- int main (void)
- {
- //local declarations
- char chInput[100];
- char chClean[100];
- //get input
- printf("This will test a string of up to 100 characters for palindromicity. \n\nEnter string ==> ");
- fgets(chInput, 100, stdin);
- //scanf("%100[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890]",chClean);
- //purge it
- fnPurge (chInput, chClean);
- //printf ("%s\n",chClean); //diagnostics
- //printf ("%s\n%s\n", chClean,chRev); //just kidding
- //test for palindromicity
- printf ("The string %s a palindrome. \n",fnTest (chClean));
- return 0;
- }
- void fnPurge (char* input, char* output)
- {
- int size;
- int outincr;
- int i;
- outincr = 0;
- size = 0;
- size = strlen(input);
- while (*input != '\0')
- {
- size = strspn(input,ALPHANUM);
- input[size] = '\0';
- strncat (output, input, 99 - strlen(output));
- input += size + 1;
- }
- return;
- }
- char* fnTest (char* output)
- {
- char reverse[100];
- int length;
- char temp;
- int i;
- length = strlen(output);
- for (i = 0; i < length; i++)
- {
- output[length - i -1] = toupper(output[length - i -1]);
- reverse[i] = output[length - i - 1];
- }
- reverse[length] = '\0';
- printf("%s %s\n",output, reverse);
- if (0 == strcmp (reverse, output)) //return text for the user
- return "is";
- else
- return "is not";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement