| | |
Terminating a String
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
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.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
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 11:44 am.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
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:
C Syntax (Toggle Plain Text)
while( ! isalpha( character ) ) { // skip the character and move on }
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Other Threads in the C Forum
- Previous Thread: string-structure
- Next Thread: Arrays: Finding Smallest String
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






