•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,676 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,272 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 5357 | Replies: 63
![]() |
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
I have a palindrome program.Is there a way to ensure user input terminated in a string by a punctuation mark (e.g. ‘!’, ‘.’, or ‘?’.) in an array? And how do i get the program to exclude commas?
eg A man, a plan, a canal, Panama! bosters a problem because when read backwards the commas are placed incorrectly whereas
A man , a plan , a cana l, Panama! would read correctly how do i make it work either way?
eg A man, a plan, a canal, Panama! bosters a problem because when read backwards the commas are placed incorrectly whereas
A man , a plan , a cana l, Panama! would read correctly how do i make it work either way?
Hmm.. a palindrome actually doesnt consider spaces, punctuation marks and character case (upper or lower).
Maybe for a more detailed explanation, you might want to look here:
http://www.daniweb.com/techtalkforums/thread59789.html
Maybe for a more detailed explanation, you might want to look here:
http://www.daniweb.com/techtalkforums/thread59789.html
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
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:
c Syntax (Toggle Plain Text)
// 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 }
Last edited by ~s.o.s~ : Nov 1st, 2006 at 10:44 am.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Palindromes are basically related to alphabets, so to ignore whitespaces in general you can traverse the whole character array, processing characters only when the
Something like:
isalpha( my_character ) condition is satisfied, otherwise skip that character.Something like:
while( ! isalpha( character ) )
{
// skip the character and move on
} I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C Forum
- Previous Thread: string-structure
- Next Thread: Arrays: Finding Smallest String



Linear Mode