Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-2008, 07:03 AM
rossen rossen is offline
Newbie
 
Join Date: Jun 2008
Posts: 4
Credits: 0
Rep Power: 0
rossen is on a distinguished road
Default C loop, giving me trouble !! Can anyone help..?

i have this code to test for palindromes, it functions perfectly well on the first test, but as the program continues to check for more after the first word it keeps printing not palindrome, once it wasnt the first word typed, run it pls, and you'll c what im talking about. Can anyone help me fix it..?

Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int isPalindrome( char *s);
int main (void)
{
int i=0;
int ch;
char s[100];
while (1){
while ((ch = getchar()) != ('\n')){
if (isalpha(ch)){
ch=toupper(ch);
s[i]=ch;
i++;
}
}
s[i]='\0';
if (isPalindrome(s) ==1){
printf("is palindrome\n");
}
else{
printf("not palindrome\n");
}
system("Pause");
return 0;
}
thanks,
-------------------------------------------

Last edited by v0id; 06-11-2008 at 08:13 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-11-2008, 07:34 AM
Chinmoy's Avatar   
Chinmoy Chinmoy is offline
Programming Professional
 
Join Date: Feb 2008
Location: where heaven meets earth
Posts: 301
Credits: 30
Rep Power: 6
Chinmoy has a spectacular aura aboutChinmoy has a spectacular aura about
Default Re: C loop, giving me trouble !! Can anyone help..?

Where is ispalindrome() defined?
__________________
God is real... unless declared an integer
my blog ::
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-11-2008, 11:08 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,479
Last Blog:
wxWidgets is NOT code ...
Credits: 815
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: C loop, giving me trouble !! Can anyone help..?

In your loop, you are continually incrementing i, so s will become something like the following:
s = "something\0else\0than\0expected\0"

You can see where you'll get issues.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-11-2008, 12:28 PM
revealer revealer is offline
Newbie
 
Join Date: Jun 2008
Posts: 9
Credits: 0
Rep Power: 0
revealer is on a distinguished road
Default Re: C loop, giving me trouble !! Can anyone help..?

I can't see isPalindrome() nor isAlpha() anywhere.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-11-2008, 01:45 PM
Xav's Avatar   
Xav Xav is online now
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,432
Last Blog:
Web slideshow in JavaS...
Credits: 1,319
Rep Power: 61
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: C loop, giving me trouble !! Can anyone help..?

Presumably the functions are defined elsewhere, as rossen managed to get the code to work.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
loop problem suicidal pencil General Programming 1 05-13-2008 07:32 PM
Javascript: Loop through ids dirkfirst JavaScript and CSS 1 07-02-2007 02:28 PM
Sounds and Sound Loop Resources TVDinner Website Design 0 03-10-2007 08:20 AM
Will loop ever terminate??? kphilux General Programming 8 03-07-2007 09:55 AM
Javaa:Tutorial - The Loop John Java Tutorials 0 12-09-2006 10:01 AM


All times are GMT -5. The time now is 02:27 PM.

Contest Stats

Xav ........ 1318.93
MeTh0Dz|Reb0rn ........ 1053.7
morefood2001 ........ 879.43
John ........ 877.37
marwex89 ........ 869.98
WingedPanther ........ 814.88
Brandon W ........ 712.1
chili5 ........ 300.72
Steve.L ........ 233.06
dcs ........ 195.72

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads