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?

Recommended Answers

All 2 Replies

You didn't post any code so I am assuming you are just interested in general help.

Check out string.h (they have a nice writeup on Wikipedia) which will give you some ideas about the kinds of string handling functions available in C.

Good luck!

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?

Get the length or the string, check the last character with the function ispunct()

And how do i get the program to exclude commas?

Copy the input line to a temp line. Use isalpha() to check if the character is a letter and copy only letters. If you want letters and numbers, use alnum() . This will exclude all non-palindrome characters.

Last thing, make sure when you do the copy you convert all the letters to upper or lower case (use toupper() or tolower() ). This is because 'A' != 'a'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.