/*
Name : Nathan Seto Kaiba
Email: New_Nathan@msn.com
Date : 04/01/2012
Program : String Use (palindrome )
Description : The goal of the program is to check the user input word is or is
not a palindrome . This program use many string functions from the
( string.h) . That will be explain with comments.
*/
#include <stdio.h> // Standard Input and Output header file
#include <stdlib.h> // Use for ( fget) function
#include <string.h> // Use for many string functions such as (strlwr)
#include <ctype.h> // Not used but include out of habit
int main ( void )
{
/*
The two array have 21 instead of 20 because of the "\0" char to end array
*/
char UserWord [21]; // char array for user input sentence
char ReverseUserWord [21]; // char array to be reverse with the (strrev)
printf(" Welcome User to the palindrome program \n\n\a" );
printf(" This program only accept a word of 20 character \n\n " );
printf(" ------------------------------------------------------ \n\n" );
printf(" Please type in your word :\n\n " );
printf(" ? " ); // Display to prompt user for input
fgets( UserWord , 20, stdin ); // used instead of (scanf) for security issues of string hack attack
// (stdin) found in (fgets) is to store the content in keyboard
strlwr( UserWord ); // Lower case complete word to deal with issues of upper case " racecar" and " Racecar"
strcpy(ReverseUserWord , UserWord); // Copy string content from Userword to ReverseUserWord
strrev( ReverseUserWord ); // Reverse the content of char array ReverseUserWord
if (strcmp (ReverseUserWord ,UserWord ) == 0) // When String compare function return 0 Display below message
{
printf ( " This word is a palindrome\n\n " );
}
else // Not a palindrome display the message below
{
printf( " This word is not a palindrome\n\n\a " );
}
getchar(); // is there a better way to hault program then getchar ?
/* What do duct tape and the force have in common ?
they both have a dark and light side and hold the universe together */
getchar();
return 0; // Program end
}
/*
Name : Nathan Seto Kaiba
Email: New_Nathan@msn.com
Date : 04/01/2012
Program : String Use (palindrome )
Description : The goal of the program is to check the user input word is or is
not a palindrome . This program use many string functions from the
( string.h) . That will be explain with comments.
*/
#include <stdio.h> // Standard Input and Output header file
#include <stdlib.h> // Use for ( fget) function
#include <string.h> // Use for many string functions such as (strlwr)
#include <ctype.h> // Not used but include out of habit
# define SIZE 21
int main ( )
{
/*
The two array have 21 instead of 20 because of the "\0" char to end array
*/
char UserWord [SIZE]; // char array for user input sentence
char ReverseUserWord [SIZE]; // char array to be reverse with the (strrev)
printf(" Welcome User to the palindrome program \n\n\a" );
printf(" This program only accept a word of 20 character \n\n " );
printf(" ------------------------------------------------------ \n\n" );
printf(" Please type in your word :\n\n " );
printf(" ? " ); // Display to prompt user for input
scanf( "%20s" , UserWord );
/*
Note : Program would not function with fget function. Wasn't able to discover why ?
Therefore used scanf with 20 as the limit char input .
fget( UserWord , 20 , stdin );
*/
strlwr( UserWord ); // Lower case complete word to deal with issues of upper case " racecar" and " Racecar"
strcpy(ReverseUserWord , UserWord); // Copy string content from Userword to ReverseUserWord
strrev( ReverseUserWord ); // Reverse the content of char array ReverseUserWord
if (strcmp (ReverseUserWord ,UserWord ) == 0) // When String compare function return 0 Display below message
{
printf ( " This word is a palindrome\n\n " );
}
else // Not a palindrome display the message below
{
printf( " This word is not a palindrome\n\n\a " );
}
getchar(); // is there a better way to hault program then getchar ?
/* What do duct tape and the force have in common ?
they both have a dark and light side and hold the universe together */
getchar();
return 0; // Program end
}