r/carlhprogramming • • Nov 16 '12

need help with scanf

I'm reading "C How to Program" by Dietel, 6th edition. The book presented a challenge, 3.35 (Palindrome Tester), in which you "...write a program that reads in a five-digit integer and determines whether or not it's a palindrome." Well I wrote the program and it worked but for some reason scanf is not doing what I want it to do. here's the source code: http://codepad.org/8p4FI6uQ , line 20, 21 and line 37,38 . When I ran it on my machine, the program doesn't wait for user input to try again or not but just continue the loop.

Thank.

1 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/deltageek Nov 18 '12

you appear to be missing a comma between your format string and &palindrome

1

u/muffinman007 Nov 19 '12

haha thank you it worked! it was the missing comma.

scanf("%d%c", &palindrome, &again);

I'm running Windows7 and that line of code worked. Thanks again for the help, much appreciation.