•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 403,490 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 4,272 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: 5224 | Replies: 63
![]() |
Well, maybe:
and your code still doesn't work
And how is this incentive for us to help you further? We aren't being lazy... :rolleyes:
Sheesh!
•
•
•
•
* how do I extract the isalpha() do I use another loop ...
* where to i make sure the two letters being compared are not case sensitive...
* where I would include a provision for the comma?
* i'm going to leave out the termination I just don't think it is necessary....
etc
•
•
•
•
I know I'm being lazy but I don't really wanna go through the motions right now .
Sheesh!
Age is unimportant -- except in cheese
•
•
Join Date: Nov 2004
Posts: 123
Reputation:
Rep Power: 0
Solved Threads: 0
Ok you're right I'll show some enthusiam, I tried to do everything you said (from what I could undertand) but it is not searching for the last character because it reports every string as not having punctuation.
int main(void)
{
char my_string[80];
int ispalindrome=1;/*boolean value True*/
int i=0;
int j=0;
void remove_newline (char *);
/* get the user input */
printf("Enter a string no more than 80 characters ");
fgets(my_string,80,stdin);
void remove_newline (char *my_string);
int string_length=strlen(my_string);
if(my_string[string_length-1]=='?'||my_string[string_length-1]=='!'
||my_string[string_length-1]=='.'){
/*If the last character is a ?,! or . continue with normal operation*/
j=string_length-1;
i = 0;
while((i <= j && ispalindrome )){
while ( ! isalpha( my_string[i] ) )
{
++ i ;
}
while( ! isalpha( my_string[j] ) )
{
--j ;
}
if(tolower (my_string[i]) != tolower(my_string[j])) {
ispalindrome = 0;
}
i++;
j--;
}
if(ispalindrome) {
printf("%s is a palindrome!\n", my_string);
}
else {
printf("sorry, %s is not a palindrome\n", my_string);
}
}
else{
printf("Your input must be terminated by a punctuation mark\n");
}
return 0;
}
void remove_newline (char *ch)
{
char *s;
s = (char *) strchr(ch,'\n');
if (s)
*s='\0';
} Last edited by boujibabe : Nov 6th, 2006 at 6:05 am.
int main(void)
{
char my_string[80];
int ispalindrome=1;/*boolean value True*/
int i=0;
int j=0;
void remove_newline (char *);
/* get the user input */
printf("Enter a string no more than 80 characters ");
fgets(my_string,80,stdin);
void remove_newline (char *my_string);
int string_length=strlen(my_string);
if(my_string[string_length-1]=='?'||my_string[string_length-1]=='!'
||my_string[string_length-1]=='.'){
/*If the last character is a ?,! or . continue with normal operation*/
j=string_length-1;
i = 0;
while((i <= j && ispalindrome )){
while ( ! isalpha( my_string[i] ) )
{
++ i ;
}
while( ! isalpha( my_string[j] ) )
{
--j ;
}
if(tolower (my_string[i]) != tolower(my_string[j])) {
ispalindrome = 0;
}
i++;
j--;
}
if(ispalindrome) {
printf("%s is a palindrome!\n", my_string);
}
else {
printf("sorry, %s is not a palindrome\n", my_string);
}
}
else{
printf("Your input must be terminated by a punctuation mark\n");
}
return 0;
}
void remove_newline (char *ch)
{
char *s;
s = (char *) strchr(ch,'\n');
if (s)
*s='\0';
}Does your code even compile ? which compiler are you using ? Wait let me guess.. is it Turbo C ?
"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."
Ah my bad.. maybe I am just going senile. Not used to writing function prototypes in main( ) and would advise you the same.
"Keep the function prototypes outside main ( ) preferably after the includes and before main ( )"
And now to the main part, what kind of errors or bugs where you gettting ?
"Keep the function prototypes outside main ( ) preferably after the includes and before main ( )"
And now to the main part, what kind of errors or bugs where you gettting ?
"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
1)It isn't reading the punctuation mark
deed!
deed
yields the same error message
2)I'm triyng to incorprate a histogram(like the one below) if it is a palindrome but I think using fgets() makes this task harder since I need to check each character and count the freqency
1 2 3 4 5
d|**
e|**
I've been going over this all night and time is slipping away...
deed!
deed
yields the same error message
2)I'm triyng to incorprate a histogram(like the one below) if it is a palindrome but I think using fgets() makes this task harder since I need to check each character and count the freqency
1 2 3 4 5
d|**
e|**
I've been going over this all night and time is slipping away...
Okay you are not callling the remove_newline( ) function. And you havent moved the function prototype outside main( ). If you dont listen closely to what I say, it would really discourage me from helping you out, coz it makes me think my efforts on you are going to waste.
Make changes and then try to test the code. I think the newline is causing problems, call remove newline and it should start working.
Make changes and then try to test the code. I think the newline is causing problems, call remove newline and it should start working.
Last edited by ~s.o.s~ : Nov 6th, 2006 at 11:59 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."
•
•
•
•
I thought I called the function here:
void remove_newline (char *my_string);
(return variable = )function( parameters ) ;
Call the function after accepting input from the user.
"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