Yes, here it is, the
program you've been waiting for! Er, ok... I wrote this
a while back and sent it to the
99 Bottles of Beer on the Wall Page, but they never put it up... Seeing as most
people have no idea what
Objective-C is, let alone what it looks like, this makes a pretty
good sample. It could be
simpler, but I wanted to do a
class to at least show that part of the
language.
main.m
#import <objc/Object.h>
#import "Beer.h"
main()
{
id beer = [[Beer alloc] init]
int i;
for (i=99; i>0; i--)
{
[beer print: i]
}
[beer free]
}
Beer.h
#import <objc/Object.h>
@interface Beer : Object
{
}
- init;
- print:(int)num;
@end
Beer.m
#import "Beer.h"
@implementation Beer
- init
{
[super init]
return self;
}
- free
{
return [super free]
}
- print:(int)num
{
char *end;
end = num != 1 ? "s" : "";
printf("%d bottle%s of beer on the wall\n", num, end);
printf("%d bottle%s of beer\n", num, end);
printf("Take one down, pass it around\n");
num--;
if (num > 1)
printf("%i bottles of beer on the wall\n\n", num);
else {
if (num ==1)
printf("%i bottle of beer on the wall\n\n", num);
else
printf("Anyone want tequilla?\n\n");
}
return self;
}
@end
This may even compile with gcc -o beer Beer.m main.m -lobjc -lpthread (if you have gcc built with Objective-C support)