•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,894 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 3,065 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: 5221 | Replies: 63
![]() |
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
heres something like it but I'm trying to integrate the punctuation mark that terminates the user input (but is not included in the assumption that the phrase is a palindrome)suggested above, but looking at it now i'm thinking the condition is better suited to while
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
char palindrome[80];
int ispalindrome=1;/*boolean value True*/
int i=0;
int j=0;
void remove_newline( char* input );
/* get the user input */
printf("Enter a word or sentence that is no more than 80 characters ");
fgets(palindrome,80,stdin);
void remove_newline( char* palindrome ){
char* p = 0 ;
if( p = strrchr( palindrome, '\n' ) )
*p = '\0' ;
}
int string_length=strlen(palindrome);
if(palindrome[string_length-1]=='?'||palindrome[string_length-1]=='!'
||palindrome[string_length-1]=='.'){
j=string_length-1;
i = 0;
while((i <= j && ispalindrome && isalpha(i) && isalpha(j) )){
if(tolower (palindrome[i]) != tolower(palindrome[j])) {
ispalindrome = 0;
}
i++;
j--;
}
if(ispalindrome) {
printf("%s is a palindrome!\n", palindrome);/* here i am supposed to print a histogram with number frequency but 'll ask later*/ }
else {
printf("sorry, %s is not a palindrome\n", palindrome);
}
}
else{
printf("Enter a word or sentence that is no more than 80 characters ");
fgets(palindrome,80,stdin);
}
return 0;
}•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
Ok let me ask your opinon I am to assume
1.The user input is terminated by a punctuation mark eg '!', '?','.'
from the way its worded i am to assumed that if the palindrome is not terminated by a punctuation mark it won't be a evaluated.Like if deed! would be a palindrome and deed would not be? I'm thinking that this assignment is poorly worded because that makes no sense a word does not need a punctuation mark.
2.The terminating punctuation mark is not used in determining if the user input is a palindrome
3. a comma cannot be used to terminate user input
1.The user input is terminated by a punctuation mark eg '!', '?','.'
from the way its worded i am to assumed that if the palindrome is not terminated by a punctuation mark it won't be a evaluated.Like if deed! would be a palindrome and deed would not be? I'm thinking that this assignment is poorly worded because that makes no sense a word does not need a punctuation mark.
2.The terminating punctuation mark is not used in determining if the user input is a palindrome
3. a comma cannot be used to terminate user input
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:
since that algo ignores anything other than alphabets, hence both:
!deed!!! and deed and deed!! will be considered as palindromes.
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.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
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.
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.
Last edited by ~s.o.s~ : Nov 5th, 2006 at 11:35 am.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
A string is terminatd by proper punctuations probably it is terminated using a full stop or should be somthing like:
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.
•
•
•
•
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.
Last edited by ~s.o.s~ : Nov 5th, 2006 at 11:45 am.
"I don't accept change. I don't deserve to live."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
![]() |
•
•
•
•
•
•
•
•
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