Deutsch English Français Italiano |
<vhacrv$2nb3$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: else ladders practice Date: Sat, 16 Nov 2024 10:14:07 -0500 Organization: A noiseless patient Spider Lines: 37 Message-ID: <vhacrv$2nb3$1@dont-email.me> References: <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> <slrnvi746p.fkp.dan@djph.net> <else-20241116103316@ram.dialup.fu-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 16 Nov 2024 16:14:09 +0100 (CET) Injection-Info: dont-email.me; posting-host="e0bec24eba10ab6028437cdac69fd7e8"; logging-data="89443"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QdX2mGDI4z1Q9Ftw3LH8EgsLZGq3nHRw=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:dGLSnoi/N+TDGjbr3hvU5BKXtqU= In-Reply-To: <else-20241116103316@ram.dialup.fu-berlin.de> Content-Language: en-US Bytes: 2295 On 11/16/24 04:42, Stefan Ram wrote: .... > My bad if the following instruction structure's already been hashed > out in this thread, but I haven't been following the whole convo! > > In my C 101 classes, after we've covered "if" and "else", > I always throw this program up on the screen and hit the newbies > with this curveball: "What's this bad boy going to spit out?". > > Well, it's a blue moon when someone nails it. Most of them fall > for my little gotcha hook, line, and sinker. > > #include <stdio.h> > > const char * english( int const n ) > { const char * result; > if( n == 0 )result = "zero"; > if( n == 1 )result = "one"; > if( n == 2 )result = "two"; > if( n == 3 )result = "three"; > else result = "four"; > return result; } > > void print_english( int const n ) > { printf( "%s\n", english( n )); } > > int main( void ) > { print_english( 0 ); > print_english( 1 ); > print_english( 2 ); > print_english( 3 ); > print_english( 4 ); } Nice. It did take a little while for me to figure out what was wrong, but since I knew that something was wrong, I did eventually find it - without first running the program.