~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Hmm.. maybe something like:Accpet the input from the user using fgets()
Remove the trailing newline at the end of the string accepted from the user. (must do, check my function remove_newline())
Check if the last character of the string is ! or ? by using something like:
// accept input
// remove trailing newline and replace with null character '\0'
int string_length = strlen( my_string ) ;
if( my_string[string_length - 1] == '?' ||
my_string[string_length - 1] == '!' )
{
// continue with the normal functionning
}
else
{
// duck out of program, using return 1 or exit(1) or again
// ask for user input
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Palindromes are basically related to alphabets, so to ignore whitespaces in general you can traverse the whole character array, processing characters only when the isalpha( my_character ) condition is satisfied, otherwise skip that character.
Something like:
while( ! isalpha( character ) )
{
// skip the character and move on
}
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Huh , which earlier program ?
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Yes its the same method.
For a well detailed and excellent algorithm see HERE.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
For a well detailed and excellent algorithm see HERE.
Thanks,S.O.S. :o
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Dumb question: I don't see the isalpha() being utilized in the final solution yet the program ignores spaces. Are you sure thats what he used?
Not a dumb question. And no, he didn't use it. But you might as well because it's easier.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Just one question before we move ahead... why do you need to terminate the string with a ! .
deed is a palindrome but deed! is not ( reverse them and you will know).
Also the algo which i described will not work for things like:
!!deed!
since that algo ignores anything other than alphabets, hence both:
!deed!!! and deed and deed!! will be considered as palindromes.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Okay try this: ( according to the requirements )
1. Accept the input from the user.
2. Check if the last character is a !
3. If it is continue with the normal palindrome processing as I have pointed out in the link before.
4. If the last char is not ! print out the message that the input is not in the specified format and then either exit the program or ask the user to reenter the string.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
A string is terminatd by proper punctuations probably it is terminated using a full stop or should be somthing like:
Ah! Satan sees Natasha.
Can you write down here the actual requirements given to you, coz this is very confusing for me. Just copy and paste the requirements given to you for me to read it.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733