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,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
Reply
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 219
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Terminating a String

  #11  
Nov 4th, 2006
Originally Posted by ~s.o.s~ View Post
For a well detailed and excellent algorithm see HERE.
Thanks, S.O.S. :o
Age is unimportant -- except in cheese
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

  #12  
Nov 4th, 2006
Dumb question: I don't see the isalpha() being utilized in the final solution yet the program ignores spaces. Are you sure thats what he used?
Last edited by boujibabe : Nov 4th, 2006 at 8:07 pm.
Reply With Quote  
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 219
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Terminating a String

  #13  
Nov 5th, 2006
Originally Posted by boujibabe View Post
Dumb question: I don't see the isalpha() being utilized in the final solution yet the program ignores spaces. Are you sure thats what he used?
Not a dumb question. And no, he didn't use it. But you might as well because it's easier.
Age is unimportant -- except in cheese
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

  #14  
Nov 5th, 2006
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;
}
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

  #15  
Nov 5th, 2006
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
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

  #16  
Nov 5th, 2006
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:
!!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."
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

  #17  
Nov 5th, 2006
Exactly my assumptions state that the user input is terminated by punctution marks but then it states that the terminating puncuation mark is not used in detmining if the user input is apalindrome. Isn't that ambiguous?
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

  #18  
Nov 5th, 2006
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.
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."
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

  #19  
Nov 5th, 2006
I tried this before above in my messy attempt but do you think that this is necessary I mean is that what the assumptims mean? No processing unless string is terminated by proper punctuation?
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

  #20  
Nov 5th, 2006
A string is terminatd by proper punctuations probably it is terminated using a full stop or should be somthing like:

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."
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 2:58 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC