Printer


Presented below is a simple program written in Objective-C.

The compile command for this program(using the GNU compiler) would be:

gcc -lobjc main.m printer.m -o test


main.m

// This will create a Printer object, set it's string and tell it to print

#import "Printer.h"

void main()
{
   id printer = [[Printer alloc] init];
   [printer addStringValue:"Hello World!"];
   [printer print];
   [printer free];
}

Printer.h

#import < objc/Object.h>


@interface Printer : Object
{
   char buffer[100];
}

- init;
- addStringValue:(const char*)astring;
- print;
- clear;

@end

Printer.m

#import "Printer.h"

@implementation Printer 

- init
{
   [super init];
   [self clear];
   return self;
}

- addStringValue:(const char*)astring
{
   strcat(buffer, astring);
   return self;
}

- print
{
   printf("%s\n",buffer);
   [self clear];
   return self;
}

- clear
{
   strcpy(buffer, "");
   return self;
}

@end