Hi,
Your question was "What's wrong with it?", let me try to answer it.
1) When you are using scanf(...) the computer is assembling 'key strokes'
    as long as you don't press the <ENTER> key. This characters will be
    stored into an invisible 'input buffer' and be taken out from there to your
    'destination' which is 'choice' (using %c, a single character every time).

    In your case, the characters that were copied into the input buffer were
    'y' followed by '\n', this is why your loop iterated only once.
    The second time 'scanf(...)' got called it extracted the '\n' from the input buffer
    and that stopped the while loop.
    You may try to use the sequence: "yYyYyyy\n" and it will result with 7 iterations
    of the loop.
2) The other problem you had was to compare (in line 14)  a pointer 'choice' to
    a char constant. The correct way to do it is to use either '*choice' or 'choice[0]'
    in the 'while condition part'.
Moshe.

-----Original Message-----
From: Kinga Kulesza [mailto:[EMAIL PROTECTED]
Sent: Monday, October 25, 2004 1:09 AM
To: [EMAIL PROTECTED]
Subject: Re: [c-prog] Novice question - Continue (Y/N)



Hopefully the moderator want scald me for persistent
asking newbee questions :-) but..... I want to come
back to my previous example. I wanted to use do while
loop and the comuter still cannot loop the operation.
Take a look on the code and output. (Coming back to
Yin's comment about main() - well that's how I'm
thaught to write my introductory programs - reffer to
"The C programing Language" - Brian W.Kernighan, Denis
M. Ritchie - not a great book and definitely not well
written for cleless.

Thanks but....

that is what I'm getting when testing the following
code:

--------------------------------------------

#include<stdio.h>
main()
{

char choice[1];

do
{
      printf("This is a simple test. Do you want to
repeat
me?\n");
      printf("continue y/n");
      printf("\n");
      scanf("%c",choice);
}
while(choice=='y' || choice=='Y');

printf("GOODBYE\n");
}
--------------------------------------
OUTPUT
--------------------------------------

css2c2% cc sample.c
"sample.c", line 1: warning: invalid white space
character in directive
"sample.c", line 14: warning: improper pointer/integer
combination: op "=="
"sample.c", line 14: warning: improper pointer/integer
combination: op "=="
"sample.c", line 17: warning: newline not last
character in file
css2c2% a.out

This is a simple test. Do you want to repeat me?
continue y/n
y
GOODBYE
css2c2%

-------------------------------------------------

Grrrrrrrr. Whats wrong with it?/

Regards

Kinga





--- "Thomas J. Hruska"
<[EMAIL PROTECTED]> wrote:

> At 02:38 PM 10/24/2004 +0800, Yin Ming writeth:
> >Oh, pardon me, I was too impolite. And, as I said,
> I'm a novice too,
> >let's share our experiece and advance together.
>
> Quick question:  Why are non-English-speakers so
> "mushy" with the English
> language?  "Let's share our experience and advance
> together" sounds like
> someone desperate for a date.  If you are wanting a
> date that badly, there
> is a simple solution to the problem:
>
> http://www.completeevil.com/geek.html
> (The Girl's Guide to Geek Guys - the definitive
> edition)
>
> Okay, jesting aside, I _want_ people to be nice on
> the list, but there is a
> point where I think people are just being overly
> nice for the sake of
> future mooching purposes...especially when people
> feel like they have
> stepped on someone else's toes they get all overly
> sensitive about each
> other's feelings.  I mean, lawsuits aren't going to
> fly here (I'll ban
> anyone from c-prog if they decide to sue someone
> else instead of settling
> an issue peaceably).  So, all I'm looking for is a
> teensy cut back on the
> mooching end of things.  A simple, "Sorry if I was
> sarcastic, I'll be
> better in the future," reply is sufficient.
>
> This isn't me playing the moderator role here.  Just
> general observations
> of the past few months and suggesting a few ideas on
> improving thread
> quality.  I understand non-native English speakers
> try really hard to sound
> good to the English speakers here (I have good
> friends from Singapore, Hong
> Kong, and Korea and know how difficult it is for
> them).  A nice gesture,
> but the finer points of the language really grind
> like sandpaper on the
> mind when used incorrectly (the same is true for
> those learning your
> respective languages).  I'm just giving a tip here
> on improving post
> quality.  Personally, I enjoy reading and writing
> e-mail "essays."  My own
> e-mails are typically first-draft quality riddled
> with errors.
>
> Of course, I don't remember what I said that was
> sarcastic, so I would have
> to go check the archives.  If I forgot it, then
> don't take it personally.
> E-mail is one of those outlets and sometimes forget
> someone real is on the
> other end.  I really need to get out more :)
>
>
> Thomas J. Hruska
> [EMAIL PROTECTED]
>
> Shining Light Productions
> Home of the Nuclear Vision scripting language and
> ProtoNova web server.
> http://www.slproweb.com/
>
>
>
>



           
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com


------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->

To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
Yahoo! Groups Links










To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=315388.5526708.6599542.3001176/D=groups/S=:HM/A=2372354/rand=467659219


Yahoo! Groups Links

Reply via email to