C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-25-2005, 11:28 AM   #1
Registered User
 
Join Date: Apr 2005
Posts: 3
Help. I don't know how to solve my problem in a program I wrote.

Hello to all.

I'm sorry but I'm just new at C programming and new to this forum as well. A friend told me that I could get some good advice regarding C programming here.

I've written a simple program while practicing the basics of C programming (and I mean BASICS - simple conditionals and scanfs...).

I'm having a problem with the program I wrote. I was able to compile and run it and it did work. The only problem was it won't wait for the user to type in the gender and the prompting of the user's home adress is a bit messy.

I was hoping you guys can solve this problem. I'll post in the code I've written. I hope someone can give me some insights on how I can solve this...

(It's really quite simple actually. I just don't know what went wrong.)

Thanks.



I attatched the file named test8.c since I can't post the whole code here...

Thanks again. More power to this forum.
Attached Files
File Type: c test8.c (1.4 KB, 18 views)
Hapster is offline   Reply With Quote
Old 04-25-2005, 11:57 AM   #2
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
Well, you're asking the user to input their gender, but then you don't actually retrieve it until you've prompted for and retrieved their address.

One thing that will probably give you problems is that scanf() leaves the trailing \n in the input buffer from when the user pressed ENTER and getchar() will grab that instead of what you're expecting it to grab.

You might want to use scanf("%c", &gender); instead of using getchar(). Or you can clear the \n off the input buffer before using getchar() to retrieve their gender.
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 04-25-2005, 11:59 AM   #3
Just Lurking
 
Dave_Sinkula's Avatar
 
Join Date: Oct 2002
Posts: 5,005
http://www.eskimo.com/~scs/C-faq/q12.18.html
http://www.eskimo.com/~scs/C-faq/q12.20.html

FAQ > How do I... (Level 1) > How do I get a number from the user (C)
FAQ > How do I... (Level 1) > Get a line of text from the user/keyboard (C)
FAQ > How do I... (Level 2) > Flush the input buffer
__________________
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Dave_Sinkula is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem during runtime (Program has stopped working...) Kaidao C++ Programming 4 03-26-2008 08:48 AM
Inheritance and Dynamic Memory Program Problem goron350 C++ Programming 1 07-02-2005 02:38 PM
Problem reading data from file and record it for use in program timmer C Programming 20 06-12-2005 11:53 PM
Problem with Program not Quitting Unregistered Windows Programming 20 06-11-2002 11:06 PM


All times are GMT -6. The time now is 12:05 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22