Language C
(poor Style)
Date: | 09/01/05 |
Author: | Matteo Casati |
URL: | n/a |
Comments: | 6 |
Info: | n/a |
Score: | (2.85 in 20 votes) |
/* The 99 Bottles of Beer Program * * Sept. 1st 2005 * by Matteo Casati <devaraja87^gmail^com> * * This is the poor-style C version of * the program. It uses only gotos. */ int main() { int n_beers=99; char pl='s'; goto a; z: return 0; b: n_beers--; if(n_beers){ pl=(n_beers==1?31:'s'); printf("%d bottle%c of beer on the wall!\n",n_beers,pl); goto a; }else{ printf("no more bottles of beer on the wall!\n"); printf("No more bottles of beer on the wall," " no more bottles of beer.\nGo to the store" " and buy some more, 99 bottles of beer on the wall!\n"); goto z; } a: printf("%d bottle%c of beer on the wall, " "%d bottle%c of beer\n",n_beers,pl,n_beers,pl); printf("Take one down and pass it around, "); goto b; }
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
actually produces correct lyrics :P | Dustshine | 08/20/05 | 0 | |
Linux kernel module | Stefan Scheler | 08/02/05 | 15 | |
Correct ANSI C containing no semicolons | Steve Checkoway | 01/15/09 | 0 | |
multithreaded version | Stefan Scheler | 05/11/05 | 4 | |
standard version | Bill Wein | 04/20/05 | 4 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Skylark said on 09/05/05 14:01:58
You have to #include <stdio.h> for that to work, ie printf lolz.
Also:
Richard Selby said on 08/25/06 17:01:29
Ah lovely! It's so nice to see someone break the rules
Kiyoshi Akima said on 08/28/06 20:04:23
In the olde days you didn't need to #include a header unless you needed something from it. Since the program doesn't use the return value from printf(), it doesn't need <stdio.h>.
However, the program does use string concatenation. Perhaps poorer style might be something like
<pre>
printf("No more bottles of beer on the wall,\
no more bottles of beer.\nGo to the store\
and buy some more, 99 bottles of beer on the wall!\n"
</pre>
Kiyoshi Akima said on 08/28/06 20:06:28
Not sure where that smiley came from. It was just a close parenthesis.
And I guess I now know not to put in formatting tags...
G. De Rosa said on 09/10/06 19:26:56
void main() would be even poorer than int main()
aName said on 11/29/08 03:28:22
"Ahh, but int main(), and not returning anything tops both "
No. If control "falls off" the end of main() without an explicit return statement, the return value is zero.