Xref: utzoo misc.misc:6088 comp.misc:6058 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcvax!ukc!warwick!geoff From: geoff@cs.warwick.ac.uk (Geoff Rimmer) Newsgroups: misc.misc,comp.misc Subject: Re: The "evil" GOTO (Was: 25 Years of BASIC) Message-ID: <1860@ubu.warwick.UUCP> Date: 10 May 89 14:31:10 GMT References: <1791@ubu.warwick.UUCP> <1436@onion.reading.ac.uk> <1814@ubu.warwick.UUCP> Sender: news@warwick.UUCP Organization: Computer Science, Warwick University, UK Lines: 54 In-reply-to: mirk@warwick.UUCP's message of 4 May 89 13:12:14 GMT Here is my solution. Which does the same as that of the original poster, and in addition: (a) it checks the buffer overflowing; (b) it checks for EOF (c) it is correct C code ----------------------------------------------------------------------------- #include main() { char str[4]; printf("Enter your sex: "); do { fflush(stdin); if (!fgets(str,3,stdin)) exit(1); } while (*str!="m" && *str!="f") ? printf("m or f only: "):0); printf("sex is %c\n",*str); } ----------------------------------------------------------------------------- In the original poster's FOLLOWUP article, he writes: > Equally invalid, (though correct) are the solutions posted by some > people of the form: > > printf (message1); > while (gets (sex), (*sex != 'm' && *sex != 'f')) > printf (message2); > > This involves a C-specific construct (the comma operator that allows > you to do lots of stuff between checks), which is one of the neat > things about C, but does nothing to remove the difficulty of > expressing some logic-routes in generic structured contructs. If you don't like these "neat tricks" as you call them, you are quite free to go choose another language to program in. However, the implication of the original posting was that you were referring to C, and that is why everyone has given answers in C. The operators like "," and "?:" are very useful, and you shouldn't complain at people for using them because they are "C-Specific". If you've got features, use em! Geoff - "You can't beat the feeling" /---------------------------------------------------------------\ | GEOFF RIMMER - Friend of COCA COLA CLASSIC | | email : geoff@uk.ac.warwick.cs | | address : Computer Science Dept, Warwick University, | | Coventry, England. | | PHONE : +44 203 692320 (9 lines) | | FAX : +44 865 726753 | \---------------------------------------------------------------/