•
•
•
•
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,960 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 2,738 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: 5222 | Replies: 63
![]() |
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
A palindrome is a word, phrase, verse, or sentence that reads the same backward or forward. For example: A man, a plan, a canal, Panama! You are required to develop a complete programming solution to determine whether the user-input is a palindrome. If this is the case, then a histogram (see Figure 1) showing the distribution of each character in the input stream is to be displayed on the screen. Only characters within the input stream should be on the vertical axis of the histogram, and each character occurrence should be represented as a special character (e.g. ‘♪’). If the user-input is not a palindrome then the user should be presented with a suitable alert message.
YOU ARE TO ASSUME:
1. The user input is no more than 80 characters long.
2. The user input may include spaces, underscores etc….
3. The user input is terminated by a punctuation mark (e.g. ‘!’, ‘.’, or ‘?’.)
4. A comma cannot be used to terminate the user-input.
5. The terminating punctuation mark is not used in determining if the user input is a palindrome.
6. The solution is case insensitive (i.e. ‘a’ and ‘A’ are treated as being the same).
YOU ARE TO ASSUME:
1. The user input is no more than 80 characters long.
2. The user input may include spaces, underscores etc….
3. The user input is terminated by a punctuation mark (e.g. ‘!’, ‘.’, or ‘?’.)
4. A comma cannot be used to terminate the user-input.
5. The terminating punctuation mark is not used in determining if the user input is a palindrome.
6. The solution is case insensitive (i.e. ‘a’ and ‘A’ are treated as being the same).
Okay the algorithm I pointed to you applies in this case, you just need to keep in mind that the last char can be a ".", "?" or a "!" but cant be a ",".
"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 it seems like you are confused between the requirement for the string to end in puctuation marks with teh concept of palindrome.
Palindrome doest care about the character case ( be it upper case or lower case ), it ignores whitespaces ( tabs, newlines, etc. ) and also ignores special characters and puctuations. It only and only cares about characters.
Terminating the string with punctutations is just a requirement of hte program, dont confuse it with palindromes.
So based on the explanatino above I ask you to tell me whether the strings given below are palindromes so that i can know you have grasped the concepts well.
De e , d
DEed
!!Deed !!!!
Deed.
Deed ?
?deed?
__de__ed__?
Give me the answers ?
Palindrome doest care about the character case ( be it upper case or lower case ), it ignores whitespaces ( tabs, newlines, etc. ) and also ignores special characters and puctuations. It only and only cares about characters.
Terminating the string with punctutations is just a requirement of hte program, dont confuse it with palindromes.
So based on the explanatino above I ask you to tell me whether the strings given below are palindromes so that i can know you have grasped the concepts well.
De e , d
DEed
!!Deed !!!!
Deed.
Deed ?
?deed?
__de__ed__?
Give me the answers ?
"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."
Bravo !!
Now that you have grasped the concept of what exactly a palindrome is , you can start coding it and then post any problems you encounter.
And please indent your code properly, so that finding errors and giving suggestions becomes simpler.
Now that you have grasped the concept of what exactly a palindrome is , you can start coding it and then post any problems you encounter.
And please indent your code properly, so that finding errors and giving suggestions becomes simpler.
"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."
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
It looks a fright and I can't figure out where I went wrong can you understand it?
int main(void)
{
char palindrome[80];
int ispalindrome=1;/*boolean value True*/
int i=0;
int j=0;
/* get the user input */
do{
printf("Enter a string no more than 80 characters ");
fgets(palindrome,80,stdin);
j = strlen(palindrome) - 1;
i = 0;
/* Remove the trailing newline*/
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]=='.'){
/*If the last character is a ?,!or . continue with normal operation*/
j=string_length-1;
i = 0;
if(j>80){
/*finds out if characters or more than 80*/
printf("Error your characters cannot be more than 80");
}
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);
}
else {
printf("sorry, %s is not a palindrome\n", palindrome);
}
}
else
printf("Your input must be terminated by a punctuation mark");
}
}while(j>80);
return 0;
} Last edited by boujibabe : Nov 5th, 2006 at 12:49 pm.
Edit your code and post your code in code tags, so that it will be easier for me to read. Read this link.
"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."
"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