User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2004
Posts: 123
Reputation: boujibabe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
boujibabe boujibabe is offline Offline
Junior Poster

Re: Terminating a String

  #21  
Nov 5th, 2006
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).
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Terminating a String

  #22  
Nov 5th, 2006
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."
Reply With Quote  
Join Date: Nov 2004
Posts: 123
Reputation: boujibabe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
boujibabe boujibabe is offline Offline
Junior Poster

Re: Terminating a String

  #23  
Nov 5th, 2006
so what if I leave out puntuation what haapens then will deed still be a palindrone?
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Terminating a String

  #24  
Nov 5th, 2006
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 ?
"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."
Reply With Quote  
Join Date: Nov 2004
Posts: 123
Reputation: boujibabe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
boujibabe boujibabe is offline Offline
Junior Poster

Re: Terminating a String

  #25  
Nov 5th, 2006
I think they all are, but now how do i conform to the requirements?
Last edited by boujibabe : Nov 5th, 2006 at 12:12 pm.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Terminating a String

  #26  
Nov 5th, 2006
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.
"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."
Reply With Quote  
Join Date: Nov 2004
Posts: 123
Reputation: boujibabe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
boujibabe boujibabe is offline Offline
Junior Poster

Re: Terminating a String

  #27  
Nov 5th, 2006
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.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Terminating a String

  #28  
Nov 5th, 2006
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."
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Terminating a String

  #29  
Nov 5th, 2006
Originally Posted by WaltP View Post
Thanks, S.O.S. :o

I know I am a bit late for this but.... the pleasure is all mine :mrgreen:
"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."
Reply With Quote  
Join Date: Nov 2004
Posts: 123
Reputation: boujibabe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
boujibabe boujibabe is offline Offline
Junior Poster

Re: Terminating a String

  #30  
Nov 5th, 2006
so can you understand it?I think there is method to the madness
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C Forum

All times are GMT -4. The time now is 7:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC